note 53427 added to function.ftell

From: Date: Wed, 01 Jun 2005 10:19:38 +0000
Subject: note 53427 added to function.ftell
Groups: php.notes 
Request: Send a blank email to php-notes+get-89732@lists.php.net to get a copy of this message
When trying to determine whether or not something was piped into a command line script, it is not smart to do a fgets(STDIN), because it will wait indefenitely if nothing is piped. Instead, I found ftell on STDIN to be very handy: it will return an integer of zero when something was piped, and nothing if nothing was piped to the script. #!/usr/bin/php4 -q <? #following will hang if nothing is piped: #$sometext = fgets(STDIN, 256) $tell = ftell(STDIN); if (is_integer($tell)==true) {echo "Something was piped: ".fread(STDIN,256)."\n";} else {echo "Nothing was piped\n";} ?> ---- Manual Page -- http://www.php.net/manual/en/function.ftell.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53427 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53427&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53427&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53427&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53427&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53427&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53427&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89732) next »