visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: fgets times out at maximum execution time in stead of default ; no control over timeout ; resume execution ?


By: Bernard France  Date: 20/09/2006 15:12:25  English  Points: 20 Status: Answered
Quality : Excellent
Hello, I'm using standard code like this :

$fd=@fopen($filename,'r'); if ($fd) { while (!feof ($fd)) { $ligne=fgets($fd, 4096); $contents []= $ligne; } fclose ($fd); } else { ... }



My problem is, sometimes the fopen() is OK but the fgets() call times out at maximum execution time (480 seconds in my case) which is ***quite*** annoying. Reading the www.php.net documentation, it seems the default time out should be 30 seconds.

Moreover, I want to have control over the time out condition so that the script execution can continue... like an "on error continue" of BASIC...

How ?

Thanks experts ;-)
By: VGR Date: 20/09/2006 21:15:32 English  Type : Answer
Hello,

I personally came up with this kind of "solution". Make good use of it.

$fd2=@fopen($filename,'r'); stream_set_blocking($fd2,FALSE); stream_set_timeout($fd2,5); // 5 secondes $notdone=FALSE; while ($notdone) { $ligne=@fgets($fd2, 4096); $info = stream_get_meta_data($fp); if ($info['timed_out']) $notdone=FALSE; else { $notdone=(!feof ($fd2)); $contents2[]= $ligne; } } // while lecture bloquante @fclose($fd2);



Do register to be able to answer

EContact
browser fav
page generated in 329.030040 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page