note 108419 added to function.fgets
| From: | dan at censornet dot com | Date: | Wed, 25 Apr 2012 12:42:39 +0000 |
| Subject: | note 108419 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187334@lists.php.net to get a copy of this message | ||
WARNING! fgets() and I presume any read() call to a file handle, e.g.
while(!feof(STDIN)) {
$line = fgets(STDIN);
...do something useful with $line...
}
...will result in a timeout after a default time of 60 seconds on my install. This behavior is non
standard (not POSIX like) and seems to me to be a bug, or if not a major caveat which should be
documented more clearly.
After the timeout fgets() will return FALSE (=== FALSE), however, you can check to see if the stream
(file handle) has really closed by checking feof($stream), e.g.
while(!feof(STDIN)) {
$line = fgets(STDIN);
if($line === FALSE) {
if(feof(STDIN)) {
break;
}
continue;
}
...do something useful with $line...
}
----
Server IP: 69.147.83.197
Probable Submitter: 94.195.239.56
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- https://master.php.net/note/edit/108419
Del: integrated -- https://master.php.net/note/delete/108419/integrated
Del: useless -- https://master.php.net/note/delete/108419/useless
Del: bad code -- https://master.php.net/note/delete/108419/bad+code
Del: spam -- https://master.php.net/note/delete/108419/spam
Del: non-english -- https://master.php.net/note/delete/108419/non-english
Del: in docs -- https://master.php.net/note/delete/108419/in+docs
Del: other reasons-- https://master.php.net/note/delete/108419
Reject -- https://master.php.net/note/reject/108419
Search -- https://master.php.net/manage/user-notes.php