in reply to When do I stop reading?

I'm crazy and just set the socket to nonblocking. Then you can use time, a character, or both to stop reading from a socket.
$flags=fcntl(SOCK,F_GETFL,0); fcntl(SOCK,F_SETFL,$flags | O_NONBLOCK);