note 45406 added to function.fgets
| From: | php-general at lists dot php dot net | Date: | Sun, 05 Sep 2004 22:05:28 +0000 |
| Subject: | note 45406 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76078@lists.php.net to get a copy of this message | ||
If you need to simulate an un-buffered fgets so that stdin doesnt hang there waiting for some input
(i.e. it reads only if there is data available) use this :
<?php
function fgets_u($pStdn) {
$pArr = array($pStdn);
if (false === ($num_changed_streams = stream_select($pArr, $write = NULL, $except = NULL, 0))) {
print("\$ 001 Socket Error : UNABLE TO WATCH STDIN.\n");
return FALSE;
} elseif ($num_changed_streams > 0) {
return trim(fgets($pStdn, 1024));
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.fgets.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45406
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45406&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45406&report=yes
Search -- http://master.php.net/manage/user-notes.php