Closed
Description
Description
The following code:
<?php
function setNonBlocking($stream)
{
var_dump($block = stream_get_meta_data($stream)['blocked']);
if ($block) {
stream_set_blocking($stream, false);
var_dump(stream_get_meta_data($stream)['blocked']);
}
}
$server = stream_socket_server("tcp://127.0.0.1:4321");
setNonBlocking($server);
$client = stream_socket_client("tcp://127.0.0.1:4321");
$res = stream_socket_accept($server);
setNonBlocking($res);
// Removing the following line will cause blocking
// stream_set_blocking($res,false);
fwrite($client,str_repeat('0',5));
var_dump(fread($res,4));
var_dump(fread($res,4));
Resulted in this output:
bool(true)
bool(false)
bool(false)
string(4) "0000"
But I expected this output instead:
bool(true)
bool(false)
bool(true)
bool(false)
string(4) "0000"
string(1) "0"
PHP Version
PHP 8.1.2, PHP 7.4.14
Operating System
Debian