I'm writing a script in PHP that uses PEAR's Net_Socket. I want to query servers to see if they have any current information. I send in a command and then use $socket->readLine() to get the response. However, if there is not a response, my script just waits forever. Is there anyway to either tell the socket to close after a specific amount of time or to wrap the whole function in a timeout, that if it hasn't returned by the timeout, it halts its execution?
Asked
Active
Viewed 462 times
1 Answers
0
On the same page you linked is a link to setTimeout(): https://pear.php.net/manual/en/package.networking.net-socket.settimeout.php
Trying calling $socket->setTimeout( $seconds, $milliseconds ); just before calling readLine()

mroselli
- 151
- 5
-
I believe that is for the time it waits to establish a connection. It did nothing to help me with this problem. – emilyk Jun 13 '13 at 14:07
-
Having read the source for the readLine method, it does seem that setting a timeout value should have an effect. Perhaps you need to experiment more with its value? – kguest Jun 13 '13 at 21:28