[php] Process_id van process via exec() command *

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
$pids[] = exec("php $url > /dev/null 2>&1 &");

Ik krijg het niet voor elkaar het process_id terug te krijgen. Om te voorkomen dat het php script dat ik aanroep blijft hangen, wil ik deze killen na x aantal seconden.

Iemand een idee?

Groet Willem

Acties:
  • 0 Henk 'm!

  • Robtimus
  • Registratie: November 2002
  • Laatst online: 19:10

Robtimus

me Robtimus no like you

string exec ( string command [, array &output [, int &return_var]])

exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
Wat zit er dan in je array (waarom geen string?)?

Misschien wat nuttige alternatieven:
shell_exec
proc_open in combinatie met proc_close en proc_terminate
popen in combinatie met pclose

Vooral die laatste 2 lijken me handig.

[ Voor 17% gewijzigd door Robtimus op 21-09-2004 11:14 ]

More than meets the eye
There is no I in TEAM... but there is ME
system specs


Acties:
  • 0 Henk 'm!

  • Wilke
  • Registratie: December 2000
  • Laatst online: 22:34
Het lijkt me niet dat dit heel veel met Non-Windows Operating Systems te maken heeft, daarom verplaats ik 'm naar Programming & Webscripting.

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ik gebruik een array omdat in een loop 6 of meer processen tegelijkertijd worden gestart, waarvan ik dus alle process_id's wil hebben. Ik heb het inmiddels opgelost, door 'echo $!' toe te voegen.
PHP:
1
2
3
4
5
while ($row = mysql_fetch_object($result)) {

$pids[] = exec("php $url > /dev/null 2>&1 & echo $!");

}

Het doorlopen van de array geeft mij nu de process_id's:
PHP:
1
2
3
foreach ($pids as $pid) {
echo $pid . "<BR>";
}

[ Voor 11% gewijzigd door gorgi_19 op 21-09-2004 11:46 ]