Languages :: PHP :: fgets times out at maximum execution time in stead of default ; no control over timeout ; resume execution ? |
|||
| By: Bernard |
Date: 20/09/2006 15:12:25 |
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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








