Hi,

Thursday, May 13, 2004, 6:57:14 AM, you wrote:
RF> Hi,

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

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

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

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


Try doing this at the error point

} elseif ($elapsed > 5) {
  echo "TOO LONG!\n";
  break 2; //kill both loops
}

-- 
regards,
Tom

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

Reply via email to