开发者

PHP - How to make php.net's sample code not hang?

The Simple TCP/IP client example will hang if no data is being received.

To see what I mean, copy the client code and run it, but remove one of the \r\n's in the GET request to make it invalid, so it looks like this:

开发者_运维知识库
$in =  "HEAD / HTTP/1.1\r\n";
$in .= "Host: www.example.com\r\n";
$in .= "Connection: Close\r\n";

The server won't respond, which is normal, but I want to be able to have a timeout or a way to keep it from hanging.

I've tried setting the timeout using socket_set_option but I think that only applies to socket_connect.

Anyone have a solution?

If I use socket_recv with a MSG_DONTWAIT flag, what is the proper way to wait for all data, connection close, or a timeout if neither of those occur?


You can use socket_select() to determine if a socket has data to be read.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜