Timeout a while loop
Posted: Thu Nov 05, 2009 6:39 am
Hello All,
I have a while loop that reads data from a socket until it reaches a specified teminator. This works but I need to be able to time this out so that if the terminator is for some reason omitted then the while loop won't wait forever. I have tried adding a incremental counter but this only ever gets up to one - whether it reads or not.
Here is my code.
Any ideas
Thanks
I have a while loop that reads data from a socket until it reaches a specified teminator. This works but I need to be able to time this out so that if the terminator is for some reason omitted then the while loop won't wait forever. I have tried adding a incremental counter but this only ever gets up to one - whether it reads or not.
Here is my code.
Code: Select all
while(substr($clients[$i]['Data'], strlen($clients[$i]['Data'])-4, 4)!="TS:\n")
{
if(false!== ($data = socket_recv($tempsock, $buf,10240,0)));
{$clients[$i]['Data'].=$buf;}
}Thanks