From: rherror404 at gmail dot com
Operating system: Windows
PHP version: 5.2.0
PHP Bug Type: Program Execution
Bug description: proc_open() descriptor spec for STDOUT append starts writing
from beginning
Description:
------------
Defining the descriptor spec for STDOUT for a call to proc_open() to
append to a file instead starts writing from beginning (not at the end as
one would expect).
C:\WINDOWS\Temp>php launch1.php
Reproduce code:
---------------
C:\WINDOWS\Temp>type launch1.php
<?
$dspec = array(0 => array("pipe", "r")
, 1 => array("file", 'C:\WINDOWS\TEMP\launch_stdout.txt', "a")
, 2 => array("file", 'C:\WINDOWS\TEMP\launch_stderr.txt', "a")
);
$i = 5; $inputpackage = serialize($i);
$proc = proc_open('php C:\WINDOWS\TEMP\launch2.php', $dspec, $pipes);
if ( is_resource($proc) ) {fwrite($pipes[0], $inputpackage);
fclose($pipes[0]);
proc_close($proc);}
$i = 2; $inputpackage = serialize($i);
$proc = proc_open('php C:\WINDOWS\TEMP\launch2.php', $dspec, $pipes);
if ( is_resource($proc) ) {fwrite($pipes[0], $inputpackage);
fclose($pipes[0]);
proc_close($proc);}
exit();
?>
C:\WINDOWS\Temp>type launch2.php
<?
function tostdout( $x ) {echo date('[Y-m-d H:i:s (T P)]') . " <PID " .
getmypid(
) . "> $x\r\n";}
$inbuffer = fgets(STDIN, 8192);
$i = unserialize($inbuffer);
for ( $j = 0; $j < $i; $j++ ) {tostdout("$j : $i"); sleep(1);}
exit();
?>
C:\WINDOWS\Temp>
Expected result:
----------------
C:\WINDOWS\Temp>type launch_stdout.txt
[2006-11-27 16:33:53 (CST -06:00)] <PID 4492> 0 : 5
[2006-11-27 16:33:54 (CST -06:00)] <PID 4492> 1 : 5
[2006-11-27 16:33:55 (CST -06:00)] <PID 4492> 2 : 5
[2006-11-27 16:33:56 (CST -06:00)] <PID 4492> 3 : 5
[2006-11-27 16:33:57 (CST -06:00)] <PID 4492> 4 : 5
[2006-11-27 16:33:58 (CST -06:00)] <PID 6808> 0 : 2
[2006-11-27 16:33:59 (CST -06:00)] <PID 6808> 1 : 2
/*
I would expect the second process to append its output
to (the end of) the output of the first process.
*/
Actual result:
--------------
C:\WINDOWS\Temp>type launch_stdout.txt
[2006-11-27 16:33:58 (CST -06:00)] <PID 6808> 0 : 2
[2006-11-27 16:33:59 (CST -06:00)] <PID 6808> 1 : 2
[2006-11-27 16:33:55 (CST -06:00)] <PID 4492> 2 : 5
[2006-11-27 16:33:56 (CST -06:00)] <PID 4492> 3 : 5
[2006-11-27 16:33:57 (CST -06:00)] <PID 4492> 4 : 5
/*
The second process has over-written lines one and two
of the output of the first process.
*/
--
Edit bug report at http://bugs.php.net/?id=39651&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39651&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39651&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39651&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39651&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39651&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39651&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39651&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39651&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39651&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39651&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39651&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39651&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39651&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39651&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39651&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39651&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39651&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39651&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39651&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39651&r=mysqlcfg