-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
hyperf/jet
#16Labels
bugSomething isn't workingSomething isn't working
Description
public function recv()
{
$buf = '';
$timeout = 1000;
stream_set_blocking($this->client, false);
// The maximum number of retries is 12, and 1000 microseconds is the minimum waiting time.
// The waiting time is doubled each time until the server writes data to the buffer.
// Usually, the data can be obtained within 1 microsecond.
return retry(12, function () use (&$buf, &$timeout) {
$read = [$this->client];
$write = null;
$except = null;
while (stream_select($read, $write, $except, 0, $timeout)) {
foreach ($read as $r) {
$buf .= fread($r, 8192);
}
}
if (! $buf) {
$timeout *= 2;
throw new RecvFailedException('No data was received');
}
return $buf;
});
}
stream_select 是在连接发生变化也会返回 1 ,也就是说客户端已经连接上,但是在接收数据的过程中对端断掉,那么
while (stream_select($read, $write, $except, 0, $timeout)) {
foreach ($read as $r) {
$buf .= fread($r, 8192);
}
}
它还是要走到这个while里面,就会造成死循环
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working