--- /dev/null
+--TEST--\r
+Bug #60120 (proc_open hangs when data in stdin/out/err is getting larger or equal to 2048)\r
+--SKIPIF--\r
+<?php\r
+if (substr(PHP_OS, 0, 3) != 'WIN') {\r
+ die('skip only for Windows');\r
+}\r
+$php = getenv('TEST_PHP_EXECUTABLE');\r
+if (!$php) {\r
+ die("No php executable defined\n");\r
+}\r
+?>\r
+--FILE--\r
+<?php\r
+\r
+error_reporting(E_ALL);\r
+\r
+$php = getenv('TEST_PHP_EXECUTABLE');\r
+if (!$php) {\r
+ die("No php executable defined\n");\r
+}\r
+$cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"';\r
+$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));\r
+$stdin = str_repeat('*', 1024 * 16) . '!';\r
+$stdin = str_repeat('*', 2049 );\r
+\r
+$options = array_merge(array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => false));\r
+$process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options);\r
+\r
+foreach ($pipes as $pipe) {\r
+ stream_set_blocking($pipe, false);\r
+}\r
+$writePipes = array($pipes[0]);\r
+$stdinLen = strlen($stdin);\r
+$stdinOffset = 0;\r
+\r
+unset($pipes[0]);\r
+\r
+while ($pipes || $writePipes) {\r
+ $r = $pipes;\r
+ $w = $writePipes;\r
+ $e = null;\r
+ $n = stream_select($r, $w, $e, 60);\r
+\r
+ if (false === $n) {\r
+ break;\r
+ } elseif ($n === 0) {\r
+ proc_terminate($process);\r
+\r
+ }\r
+ if ($w) {\r
+ $written = fwrite($writePipes[0], (binary)substr($stdin, $stdinOffset), 8192);\r
+ if (false !== $written) {\r
+ $stdinOffset += $written;\r
+ }\r
+ if ($stdinOffset >= $stdinLen) {\r
+ fclose($writePipes[0]);\r
+ $writePipes = null;\r
+ }\r
+ }\r
+\r
+ foreach ($r as $pipe) {\r
+ $type = array_search($pipe, $pipes);\r
+ $data = fread($pipe, 8192);\r
+ if (false === $data || feof($pipe)) {\r
+ fclose($pipe);\r
+ unset($pipes[$type]);\r
+ }\r
+ }\r
+}\r
+echo "OK.";\r
+?>\r
+--EXPECT--\r
+OK.\r