I'm trying to grab information from a socket and 90% of the time everything goes right. However, every now and then, the hardware I'm communicating with stops feeding the buffer, and my script "hangs" while trying to grab the next byte from the input buffer. My code is rediculously ugly and complicated so I will give you the pretty, short version.
$handle = pfsockopen($ip,$port,$eNum,$eStr,10); // $ip and $port have been defined.
while(true) {
$x = fgets($handle,1); // it halts here when buffer is empty
if (ord($x) == 6) // ASCII code 6 is the end of data identifier
break;
}
fclose($handle);
There's a whole lot more to this, but this is the only important part you need to see. According to the hardware specs, I'm supposed to continue grabbing byte after byte until I reach the character with the ASCII code 6. The code works, but the hardware sometimes fails and the script hangs at the fgets() function. The 10-second timeout doesn't work but the 30 second pre-defined maximum script execution option halts the entire program. That's not good. I don't want the program to stop. I need to continue even if there is an error with the timelimit.
What I need is some code that will "know" that the hardware has taken a longtime to give us anything and it should only stop the fgets() function. I don't want it to exit the entire program.
Please help.
Rubric