views:

23

answers:

1

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?

+1  A: 

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

Ignacio Vazquez-Abrams
Can't believe I didn't notice that function on the php.net site, thanks.
guitar-