note 92397 added to function.fgets

From: Date: Thu, 23 Jul 2009 00:07:54 +0000
Subject: note 92397 added to function.fgets
Groups: php.notes 
Request: Send a blank email to php-notes+get-158600@lists.php.net to get a copy of this message
One thing I discovered with fgets, at least with PHP 5.1.6, is that you may have to use an IF statement to avoid your code running rampant (and possibly hanging the server). This can cause problems if you do not have root access on the server on which you are working. This is the code I have implemented ($F1 is an array): <?php if($fh = fopen("filename","r")){ while (!feof($fh)){ $F1[] = fgets($fh,9999); } fclose($fh); ?> I have noticed that without the IF statement, fgets seems to ignore when $fh is undefined (i.e., "filename" does not exist). If that happens, it will keep attempting to read from a nonexistent filehandle until the process can be administratively killed or the server hangs, whichever comes first. ---- Server IP: 208.69.120.35 Probable Submitter: 138.163.128.42 ---- Manual Page -- http://www.php.net/manual/en/function.fgets.php Edit -- https://master.php.net/note/edit/92397 Del: integrated -- https://master.php.net/note/delete/92397/integrated Del: useless -- https://master.php.net/note/delete/92397/useless Del: bad code -- https://master.php.net/note/delete/92397/bad+code Del: spam -- https://master.php.net/note/delete/92397/spam Del: non-english -- https://master.php.net/note/delete/92397/non-english Del: in docs -- https://master.php.net/note/delete/92397/in+docs Del: other reasons-- https://master.php.net/note/delete/92397 Reject -- https://master.php.net/note/reject/92397 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158600) next »