Skip to content

Commit fae78d8

Browse files
nielsdosaetonsi
andcommitted
Add a regression test for GH-10031
Co-authored-by: aetonsi <18366087+aetonsi@users.noreply.github.com>
1 parent c930230 commit fae78d8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
GH-10031 ([Stream] STREAM_NOTIFY_PROGRESS over HTTP emitted irregularly for last chunk of data)
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6+
?>
7+
--INI--
8+
allow_url_fopen=1
9+
--CONFLICTS--
10+
server
11+
--FILE--
12+
<?php
13+
14+
$serverCode = <<<'CODE'
15+
$fsize = 1000;
16+
$chunksize = 99;
17+
$chunks = floor($fsize / $chunksize); // 10 chunks * 99 bytes
18+
$lastchunksize = $fsize - $chunksize * $chunks; // 1 chunk * 10 bytes
19+
20+
header("Content-Length: " . $fsize);
21+
flush();
22+
for ($chunk = 1; $chunk <= $chunks; $chunk++) {
23+
echo str_repeat('x', $chunksize);
24+
@ob_flush();
25+
usleep(50 * 1000);
26+
}
27+
28+
echo str_repeat('x', $lastchunksize);
29+
CODE;
30+
31+
include __DIR__."/../../../../sapi/cli/tests/php_cli_server.inc";
32+
php_cli_server_start($serverCode, null, []);
33+
34+
$context = stream_context_create(['http' => ['ignore_errors' => true,]]);
35+
$lastBytesTransferred = 0;
36+
stream_context_set_params($context, ['notification' => function ($code, $s, $m, $mc, $bytes_transferred, $bytes_max)
37+
use (&$lastBytesTransferred) {
38+
if ($code === STREAM_NOTIFY_FILE_SIZE_IS) echo "expected filesize=$bytes_max".PHP_EOL;
39+
$lastBytesTransferred = $bytes_transferred;
40+
@ob_flush();
41+
}]);
42+
43+
$get = file_get_contents("http://".PHP_CLI_SERVER_ADDRESS, false, $context);
44+
45+
echo "got filesize=" . strlen($get) . PHP_EOL;
46+
var_dump($lastBytesTransferred);
47+
48+
?>
49+
--EXPECT--
50+
expected filesize=1000
51+
got filesize=1000
52+
int(1000)

0 commit comments

Comments
 (0)