bug60120.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Bug #60120 (proc_open hangs when data in stdin/out/err is getting larger or equal to 2048)
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) != 'WIN') {
  6. die('skip only for Windows');
  7. }
  8. $php = getenv('TEST_PHP_EXECUTABLE');
  9. if (!$php) {
  10. die("No php executable defined\n");
  11. }
  12. ?>
  13. --FILE--
  14. <?php
  15. error_reporting(E_ALL);
  16. $php = getenv('TEST_PHP_EXECUTABLE');
  17. if (!$php) {
  18. die("No php executable defined\n");
  19. }
  20. $cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"';
  21. $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
  22. $stdin = str_repeat('*', 1024 * 16) . '!';
  23. $stdin = str_repeat('*', 2049 );
  24. $options = array_merge(array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => false));
  25. $process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options);
  26. foreach ($pipes as $pipe) {
  27. stream_set_blocking($pipe, false);
  28. }
  29. $writePipes = array($pipes[0]);
  30. $stdinLen = strlen($stdin);
  31. $stdinOffset = 0;
  32. unset($pipes[0]);
  33. while ($pipes || $writePipes) {
  34. $r = $pipes;
  35. $w = $writePipes;
  36. $e = null;
  37. $n = stream_select($r, $w, $e, 60);
  38. if (false === $n) {
  39. break;
  40. } elseif ($n === 0) {
  41. proc_terminate($process);
  42. }
  43. if ($w) {
  44. $written = fwrite($writePipes[0], (binary)substr($stdin, $stdinOffset), 8192);
  45. if (false !== $written) {
  46. $stdinOffset += $written;
  47. }
  48. if ($stdinOffset >= $stdinLen) {
  49. fclose($writePipes[0]);
  50. $writePipes = null;
  51. }
  52. }
  53. foreach ($r as $pipe) {
  54. $type = array_search($pipe, $pipes);
  55. $data = fread($pipe, 8192);
  56. if (false === $data || feof($pipe)) {
  57. fclose($pipe);
  58. unset($pipes[$type]);
  59. }
  60. }
  61. }
  62. echo "OK.";
  63. ?>
  64. --EXPECT--
  65. OK.