Annotation of embedaddon/php/ext/standard/tests/file/bug60120.phpt, revision 1.1.1.1

1.1       misho       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: 
                     16: error_reporting(E_ALL);
                     17: 
                     18: $php = getenv('TEST_PHP_EXECUTABLE');
                     19: if (!$php) {
                     20:        die("No php executable defined\n");
                     21: }
                     22: $cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"';
                     23: $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
                     24: $stdin = str_repeat('*', 1024 * 16) . '!';
                     25: $stdin = str_repeat('*', 2049 );
                     26: 
                     27: $options = array_merge(array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => false));
                     28: $process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options);
                     29: 
                     30: foreach ($pipes as $pipe) {
                     31:     stream_set_blocking($pipe, false);
                     32: }
                     33: $writePipes = array($pipes[0]);
                     34: $stdinLen = strlen($stdin);
                     35: $stdinOffset = 0;
                     36: 
                     37: unset($pipes[0]);
                     38: 
                     39: while ($pipes || $writePipes) {
                     40:     $r = $pipes;
                     41:     $w = $writePipes;
                     42:     $e = null;
                     43:     $n = stream_select($r, $w, $e, 60);
                     44: 
                     45:     if (false === $n) {
                     46:         break;
                     47:     } elseif ($n === 0) {
                     48:         proc_terminate($process);
                     49: 
                     50:     }
                     51:     if ($w) {
                     52:         $written = fwrite($writePipes[0], (binary)substr($stdin, $stdinOffset), 8192);
                     53:         if (false !== $written) {
                     54:             $stdinOffset += $written;
                     55:         }
                     56:         if ($stdinOffset >= $stdinLen) {
                     57:             fclose($writePipes[0]);
                     58:             $writePipes = null;
                     59:         }
                     60:     }
                     61: 
                     62:     foreach ($r as $pipe) {
                     63:         $type = array_search($pipe, $pipes);
                     64:         $data = fread($pipe, 8192);
                     65:         if (false === $data || feof($pipe)) {
                     66:             fclose($pipe);
                     67:             unset($pipes[$type]);
                     68:         }
                     69:     }
                     70: }
                     71: echo "OK.";
                     72: ?>
                     73: --EXPECT--
                     74: OK.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>