import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-file / bug60120.php
blobf86a502a4ae985d540dd7eac2a3fd3f50435226b
1 <?php
3 error_reporting(E_ALL);
5 $php = getenv('TEST_PHP_EXECUTABLE');
6 if (!$php) {
7 die("No php executable defined\n");
9 $cmd = 'php -r "fwrite(STDOUT, $in = file_get_contents(\'php://stdin\')); fwrite(STDERR, $in);"';
10 $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
11 $stdin = str_repeat('*', 1024 * 16) . '!';
12 $stdin = str_repeat('*', 2049 );
14 $options = array_merge(array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => false));
15 $process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options);
17 foreach ($pipes as $pipe) {
18 stream_set_blocking($pipe, false);
20 $writePipes = array($pipes[0]);
21 $stdinLen = strlen($stdin);
22 $stdinOffset = 0;
24 unset($pipes[0]);
26 while ($pipes || $writePipes) {
27 $r = $pipes;
28 $w = $writePipes;
29 $e = null;
30 $n = stream_select($r, $w, $e, 60);
32 if (false === $n) {
33 break;
34 } elseif ($n === 0) {
35 proc_terminate($process);
38 if ($w) {
39 $written = fwrite($writePipes[0], (binary)substr($stdin, $stdinOffset), 8192);
40 if (false !== $written) {
41 $stdinOffset += $written;
43 if ($stdinOffset >= $stdinLen) {
44 fclose($writePipes[0]);
45 $writePipes = null;
49 foreach ($r as $pipe) {
50 $type = array_search($pipe, $pipes);
51 $data = fread($pipe, 8192);
52 if (false === $data || feof($pipe)) {
53 fclose($pipe);
54 unset($pipes[$type]);
58 echo "OK.";