|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-05-17 08:54 UTC] pcdinh at gmail dot com
[2010-05-17 09:40 UTC] pcdinh at gmail dot com
-Package: PCNTL related
+Package: Program Execution
[2010-05-17 09:40 UTC] pcdinh at gmail dot com
[2010-05-18 12:47 UTC] mike@php.net
-Status: Open
+Status: Bogus
[2010-05-18 12:47 UTC] mike@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 14:00:01 2025 UTC |
Description: ------------ I write a script that is able to launch another process which runs in 100 seconds The master process will check the child process in a loop to see if it is still running. The child process is able to launch and run correctly. However, when I asign the resource returned by proc_get_status() to an array and return that array from a function, proc_get_status() does not work correctly any more. It caused the child process exit right after the first call. Called in the same scope ======================== $process = proc_open('/usr/local/php5-fcgi/bin/php process1.php', $descriptors, $pipes); // $process and proc_get_status() in same scope ==> OK $status = proc_get_status($process); if (true === $status['running']) { echo "Started process Id\n"; } else { echo "Unable to start a process\n"; } Called from different scope and against a reference =================================================== Return from a function ====================== return array( 'pid' => $status['pid'], 'handle' => $process ); Called against a reference ========================== foreach ($running as $pid => $info) { // first call will cause child process exit after that $status = proc_get_status($info['handle']); sleep(1); } Test script: --------------- You can read the sample code here: http://gist.github.com/403467 It contains 2 files: a master process named test3.php and a child process named process1.php Expected result: ---------------- [root@clipserver test]# ./test3.php Parent process ID: 30283 Started process Id Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process 30284 is running Caught a SIGCHLD signal, a worker process exiting Child process 30284 exited with status 0 Command used Termination signal: Is stopped: Stop signal: Process 30284 is not running Process 30284 is not running Process 30284 is not running Actual result: -------------- [root@clipserver test]# ./test3.php Parent process ID: 30283 Started process Id Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process Id 30284 is running Command used /usr/local/php5-fcgi/bin/php process1.php Process 30284 is running Caught a SIGCHLD signal, a worker process exiting Child process 30284 exited with status 0 Command used Termination signal: Is stopped: Stop signal: Process 30284 is not running Process 30284 is not running Process 30284 is not running