php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39651 proc_open() descriptor spec for STDOUT append starts writing from beginning
Submitted: 2006-11-27 22:49 UTC Modified: 2007-09-12 11:47 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rherror404 at gmail dot com Assigned: nlopess (profile)
Status: Closed Package: Program Execution
PHP Version: 5 OS: win32 only
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rherror404 at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-27 22:49 UTC] rherror404 at gmail dot com
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.
*/

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-27 23:09 UTC] tony2001@php.net
Not reproducible on Linux.
 [2007-01-01 15:25 UTC] nlopess@php.net
I do verify the bug, but I wasn't able to fix it.
The problem is that I think windows doesn't support the append mode when using HANDLEs. So, when we call _get_osfhandle() to convert the fd to an HANDLE, windows loose this information. (yes, we need to convert to an handle because CreateProcess() requires it).
I'm leacing open as someone might have some idea (no, I don't know how to emulate it, as after "forking" we loose the control over the new process..)
 [2007-09-05 13:53 UTC] jani@php.net
Nuno, please check the version field here. It must never be '*' like it was before I set it to something meaningful. If you can reproduce this with PHP 5.2.4, set the version to it.
 [2007-09-12 11:47 UTC] nlopess@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

the append mode is now emulated using a fseek().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 08:01:28 2024 UTC