From:
Operating system: CentOS 5.4
PHP version: 5.2.13
Package: PCNTL related
Bug Type: Bug
Bug description:proc_get_status() caused child process exit
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:
----------------
[r...@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:
--------------
[r...@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
--
Edit bug report at http://bugs.php.net/bug.php?id=51836&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51836&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51836&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51836&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51836&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51836&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51836&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51836&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51836&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51836&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51836&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51836&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51836&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51836&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51836&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51836&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51836&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51836&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51836&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51836&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51836&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51836&r=mysqlcfg