Hi,

I have this code (below) that waits for particular data to come over the socket ("ENX"), at which point it breaks out of the loop and does other things. Presently, it will loop forever, until it receives "ENX"—a good start—but I also need it to break-out if the loop runs longer than five seconds. This is where I'm having a problem. It seems that it is only reading once data comes over the socket, so it is stuck on that first 'while' line ("while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {").

        $timer = time();
        while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {
                $data .= $buf;
                $elapsed = time() - $timer;     
                if(preg_match("/ENX/", $data)) {
                        break;
                        } elseif ($elapsed > 5) {
                        echo "TOO LONG!\n";
                        break;
                        }
                }

Maybe set non-blocking / blocking socket is the answer? Only problem is I can't find much [good] documentation describing what blocking and non-blocking sockets are good for, etc. Any ideas? Thanks.

...Rene
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to