Test for end-of-file on a file pointer in PHP
Description
The following code shows how to test for end-of-file on a file pointer.
Example
<?php/*from w ww . j a v a2 s . c om*/
function safe_feof($fp, &$start = NULL) {
$start = microtime(true);
return feof($fp);
}
/* Assuming $fp is previously opened by fsockopen() */
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
$start = NULL;
$timeout = ini_get('default_socket_timeout');
while(!safe_feof($fp, $start) && (microtime(true) - $start) < $timeout)
{
/* Handle */
}
?>