Bug #51800 [Opn->Ver]: proc_open on Windows hangs forever

From: Date: Mon, 09 Apr 2012 12:33:09 +0000
Subject: Bug #51800 [Opn->Ver]: proc_open on Windows hangs forever
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-169349@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
 Updated by:         pajoye@php.net
 Reported by:        ph dot wolfer at googlemail dot com
 Summary:            proc_open on Windows hangs forever
-Status:             Open
+Status:             Verified
 Type:               Bug
 Package:            Streams related
 Operating System:   Windows
 PHP Version:        5.2.13
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[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 (#169349) next »