php socket_recvfrom failed randomly

时间:2018-06-19 11:09:02

标签: php sockets

This code works fine in most time, but fail randomly.

foreach ($blocks as $block) {
    $this->socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
    socket_connect($this->socket, $this->ipcFilePath);

    socket_send($this->socket, $msg, strlen($msg), 0);

    if (socket_recvfrom($this->socket, $buf, 1024 * 1024, 0, $source) === false) {
        throw new \Exception('Read failed for ' . $this->ipcFilePath);
    }
    Log::info(strlen($buf));

    socket_close($this->socket);
}

The failure means socket_recvfrom returns content of a very specific size 36544 instead of full content of a longer size. The length is always 36544. Does this number special?

I used to think maybe the buf size is not big enough. But the log shows even with an output of 110000 bytes, it successes. This failure occurs just randomly.

0 个答案:

没有答案