1--TEST--
2Bug #51056 (fread() on blocking stream will block even if data is available)
3--FILE--
4<?php
5
6$serverCode = <<<'CODE'
7$server = stream_socket_server('tcp://127.0.0.1:64327');
8phpt_notify();
9
10$conn = stream_socket_accept($server);
11
12fwrite($conn, "Hello 1\n"); // 8 bytes
13usleep(50000);
14fwrite($conn, str_repeat('a', 300)."\n"); // 301 bytes
15usleep(50000);
16fwrite($conn, "Hello 1\n"); // 8 bytes
17
18fclose($conn);
19fclose($server);
20CODE;
21
22$clientCode = <<<'CODE'
23
24phpt_wait();
25
26$fp = fsockopen("tcp://127.0.0.1:64327");
27
28while (!feof($fp)) {
29    $data = fread($fp, 256);
30    $bytes = strlen($data);
31    if ($bytes > 0) {
32        printf("fread read %d bytes\n", $bytes);
33    }
34}
35CODE;
36
37include sprintf("%s/../../../openssl/tests/ServerClientTestCase.inc", __DIR__);
38ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
39
40?>
41--EXPECT--
42fread read 8 bytes
43fread read 256 bytes
44fread read 45 bytes
45fread read 8 bytes
46