Skip to content

Commit f733774

Browse files
Girgiasarnaud-lb
andcommitted
Add stream test that loses buffer after cast
Co-authored-by: Arnaud Le Blanc <[email protected]>
1 parent a3e1a12 commit f733774

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Casting a stream can lose data and needs to emit a warning
3+
--FILE--
4+
<?php
5+
6+
$tempnam = tempnam(sys_get_temp_dir(), 'test');
7+
8+
$stream = popen('echo 1; echo 2; rm ' . escapeshellarg($tempnam), 'r');
9+
10+
do {
11+
usleep(10);
12+
clearstatcache();
13+
} while (file_exists($tempnam));
14+
15+
// fills the read buffer with up to 8192 bytes
16+
fgets($stream);
17+
18+
// cast $stream and read fd until eof. Print each line that was read, prefixed with "proc open stdin:"
19+
$process = proc_open(
20+
'sed "s/^/proc open stdin:/"',
21+
[
22+
0 => $stream,
23+
1 => ['pipe', 'w'],
24+
],
25+
$pipes,
26+
);
27+
28+
var_dump(stream_get_contents($pipes[1]));
29+
30+
?>
31+
--EXPECTF--
32+
Warning: proc_open(): 2 bytes of buffered data lost during stream conversion! in %s on line %d
33+
string(0) ""

0 commit comments

Comments
 (0)