How do I force my script to exit after 5 seconds?
| From: | Aaron Gould | Date: | Thu, 22 Feb 2007 15:06:28 +0000 |
| Subject: | How do I force my script to exit after 5 seconds? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-249239@lists.php.net to get a copy of this message | ||
I have a script that connects to a networked device via PHP's socket functions. This device accepts proprietary commands (e.g.: "KPRINT", as seen below), and returns data. However, this device does not have any sort of "EXIT" command to end the processing of events. So it essentially loops forever.
I do know that if this device does not return anything after 5 seconds, it will never return anything.
So, my question is: how can I force this script to stop after 5 seconds has elapsed?
Here's the script:
============================================================
$fp = fsockopen('192.168.3.25', 10001, $errno, $errstr, 5);
if (!$fp) {
echo 'Error...';} else {
$command = "KPRINT\r\n";
fwrite($fp, $command);
while (!feof($fp)) {
$buffer = fgets($fp, 1024);
}
fclose($fp);} ============================================================ Thanks!