1--TEST--
2GH-10031 ([Stream] STREAM_NOTIFY_PROGRESS over HTTP emitted irregularly for last chunk of data)
3--SKIPIF--
4<?php
5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6?>
7--INI--
8allow_url_fopen=1
9--CONFLICTS--
10server
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
20header("Content-Length: " . $fsize);
21flush();
22for ($chunk = 1; $chunk <= $chunks; $chunk++) {
23    echo str_repeat('x', $chunksize);
24    @ob_flush();
25    usleep(50 * 1000);
26}
27
28echo str_repeat('x', $lastchunksize);
29CODE;
30
31include __DIR__."/../../../../sapi/cli/tests/php_cli_server.inc";
32php_cli_server_start($serverCode, null, []);
33
34$context = stream_context_create(['http' => ['ignore_errors' => true,]]);
35$lastBytesTransferred = 0;
36stream_context_set_params($context, ['notification' => function ($code, $s, $m, $mc, $bytes_transferred, $bytes_max)
37use (&$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
45echo "got filesize=" . strlen($get) . PHP_EOL;
46var_dump($lastBytesTransferred);
47
48?>
49--EXPECT--
50expected filesize=1000
51got filesize=1000
52int(1000)
53