Bug #51800 [Com]: proc_open on Windows hangs forever

From: Date: Sat, 16 Mar 2013 03:15:07 +0000
Subject: Bug #51800 [Com]: proc_open on Windows hangs forever
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-177830@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=51800&edit=1

 ID:                 51800
 Comment by:         hanskrentel at yahoo dot de
 Reported by:        ph dot wolfer at googlemail dot com
 Summary:            proc_open on Windows hangs forever
 Status:             Assigned
 Type:               Bug
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        *
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

The problem with exactly 4097 bytes has just been reported here: 
https://bugs.php.net/bug.php?id=64438

It's a follow up to https://bugs.php.net/bug.php?id=60120 which is
wrongly closed 
as resolved.

this and the many other issues show that the flaw is not fixed:

https://bugs.php.net/bug.php?id=51800
https://bugs.php.net/bug.php?id=60120
https://bugs.php.net/bug.php?id=64438


Previous Comments:
------------------------------------------------------------------------
[2012-04-12 14:41:35] andremiguelcruz at msn dot com

I hope this gets fixed soon both on 5.4 and 5.3.
Is very frustrating because I have this bug while using symfony2 with scss.

------------------------------------------------------------------------
[2012-04-09 12:49:12] pajoye@php.net

it seems that the issue is on main/streams.c:679

		if (stream->writepos - stream->readpos < (off_t)size) {

where writepos and readpos are equals.

Anatolyi, please take a look at it.

------------------------------------------------------------------------
[2012-04-08 21:21:34] seld@php.net

I could reproduce this on PHP 5.4.0 as soon as $data is longer than 4096 bytes.

With $data = str_repeat("a", 4097); in process.php it hangs forever, while with any number
until 4096 it passes.

------------------------------------------------------------------------
[2012-02-19 14:37:42] nicolas dot sauveur at gmail dot com

This seems similar as https://bugs.php.net/bug.php?id=60120 .

Only partially fixed for me ( thus not fixed ) in php 5.3.9.

------------------------------------------------------------------------
[2010-05-12 17:31:30] ph dot wolfer at googlemail dot com

Description:
------------
On Windows, if you use proc_open to open another process and if you use a pipe for STDERR, the
script will hang when trying to read from STDOUT or STDERR if the opened process outputs a lot of
data.

See the example below. The called script process.php is a simple script which writes some data to
STDOUT and STDERR:

$data = str_repeat("a", 10000); 
fwrite(STDOUT, $data);
fwrite(STDERR, $data);
exit(0);

If called as shown below, the script will hang in the loop that reads the STDOUT pipe. The same
would happen if you would read the STDERR pipe before. If you lower the amount of data in
process.php the script will run to the end. In my tests everything below ~2000 bytes was ok, above
this value the script hang.

If you change the script below to not include the STDERR descriptor or if you change the STDERR
descriptor to a file output everything will work fine. Also if you close the STDERR pipe before
reading from STDOUT it will work. There seems to be some deadlock.

The same script works fine on Linux.

This was tested with Windows Server 2008, IIS, PHP 5.2.13. But I have seen this on other Windows
configurations as well.

Test script:
---------------
<?php
$cmd = "\"C:/Program Files/php/php.exe\" process.php";

$status;
$stdout = "";
$stderr = "";
$pipes = array();

$descriptors = array(
	0 => array("pipe", "r"),	// stdin
	1 => array("pipe", "w"),	// stdout
	2 => array("pipe", "w")		// stderr
	);
$process = proc_open($cmd, $descriptors, $pipes);
	
if (is_resource($process))
{
	fclose($pipes[0]);
	
	while (!feof($pipes[1]))
		$stdout .= fread($pipes[1], 1024);
	fclose($pipes[1]);
	
	while (!feof($pipes[2]))
		$stderr .= fread($pipes[2], 1024);
	fclose($pipes[2]);
	
	$status = proc_close($process);
}

print_r(array(
	"status" => $status,
	"stdout" => $stdout,
	"stderr" => $stderr,
));
?>



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51800&edit=1


Thread (16 messages)

« previous php.bugs (#177830) next »