开发者

Socket PHP hangs on fgets

I have server and client application in JAVA, what working with this server. On first look, it's no problems - JAVA uses socket.getInputStream() for receiving data and socket.getOutputStream() for sending data.

I need to write same client on PHP. All examples from manuals didn't help me. I can succesfully connect to server, but when i trying to read something - page hangs. For example:

$fp = stream_so开发者_运维问答cket_client($addr, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, $data);
    while (!feof($fp)) {
        var_dump(fgets($fp, 1024));
    }
    fclose($fp);
}

This code hangs even without while.

What can be wrong?


Does your server really send bytes?

fgets($fp, 1024)

returns, if one of these conditions happens:

- EOF or newline received

- 1024-1 bytes read

or the far side closed the connection.

If these conditions do not happen, the call blocks.

How about changing 1024 to a lower number or use fgetc()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜