@@ -6,14 +6,15 @@ $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
6
6
if (!$ php ) {
7
7
die ("skip No php executable defined \n" );
8
8
}
9
+ if (PHP_OS_FAMILY === 'Windows ' ) die ('skip not for Windows ' );
9
10
?>
10
11
--FILE--
11
12
<?php
12
13
13
14
error_reporting (E_ALL );
14
15
15
16
$ php = getenv ('TEST_PHP_EXECUTABLE_ESCAPED ' );
16
- $ cmd = $ php . ' -r "fwrite(STDOUT, $in = file_get_contents( \'php://stdin \')); fwrite(STDERR, $in);" ' ;
17
+ $ cmd = $ php . ' -r "\ $in = file_get_contents( \'php://stdin \'); fwrite(STDOUT, \$in ); fwrite(STDERR, \ $in);" ' ;
17
18
$ descriptors = array (array ('pipe ' , 'r ' ), array ('pipe ' , 'w ' ), array ('pipe ' , 'w ' ));
18
19
$ stdin = str_repeat ('* ' , 2049 );
19
20
@@ -29,6 +30,7 @@ $stdinOffset = 0;
29
30
30
31
unset($ pipes [0 ]);
31
32
33
+ $ procOutput = [];
32
34
while ($ pipes || $ writePipes ) {
33
35
$ r = $ pipes ;
34
36
$ w = $ writePipes ;
@@ -45,6 +47,8 @@ while ($pipes || $writePipes) {
45
47
$ written = fwrite ($ writePipes [0 ], substr ($ stdin , $ stdinOffset ), 8192 );
46
48
if (false !== $ written ) {
47
49
$ stdinOffset += $ written ;
50
+ } else {
51
+ die ('Failed to write to pipe ' );
48
52
}
49
53
if ($ stdinOffset >= $ stdinLen ) {
50
54
fclose ($ writePipes [0 ]);
@@ -55,12 +59,21 @@ while ($pipes || $writePipes) {
55
59
foreach ($ r as $ pipe ) {
56
60
$ type = array_search ($ pipe , $ pipes );
57
61
$ data = fread ($ pipe , 8192 );
58
- if (false === $ data || feof ($ pipe )) {
62
+ if (feof ($ pipe )) {
59
63
fclose ($ pipe );
60
64
unset($ pipes [$ type ]);
65
+ } elseif (false === $ data ) {
66
+ die ('Failed to read from pipe ' );
67
+ } else {
68
+ $ procOutput [$ type ] = ($ procOutput [$ type ] ?? '' ) . $ data ;
61
69
}
62
70
}
63
71
}
72
+ foreach ($ procOutput as $ output ) {
73
+ if ($ output !== $ stdin ) {
74
+ die ('Output does not match input: ' . $ output );
75
+ }
76
+ }
64
77
echo "OK. " ;
65
78
?>
66
79
--EXPECT--
0 commit comments