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:0'); 8phpt_notify_server_start($server); 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 24$fp = fsockopen("tcp://{{ ADDR }}"); 25 26while (!feof($fp)) { 27 $data = fread($fp, 256); 28 $bytes = strlen($data); 29 if ($bytes > 0) { 30 printf("fread read %d bytes\n", $bytes); 31 } 32} 33CODE; 34 35include sprintf("%s/../../../openssl/tests/ServerClientTestCase.inc", __DIR__); 36ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 37 38?> 39--EXPECT-- 40fread read 8 bytes 41fread read 256 bytes 42fread read 45 bytes 43fread read 8 bytes 44