#35507 [Fbk->Opn]: feof does not report no-char on STDIN

From: Date: Thu, 01 Dec 2005 19:08:59 +0000
Subject: #35507 [Fbk->Opn]: feof does not report no-char on STDIN
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-89600@lists.php.net to get a copy of this message
ID: 35507 User updated by: dsp at tdcspace dot dk Reported By: dsp at tdcspace dot dk -Status: Feedback +Status: Open Bug Type: Feature/Change Request Operating System: win/nix PHP Version: 5.1.1 New Comment: Tx for asking me ! In case of the keyboard input, the state is well defined from the bios aka. the "waiting char status" of which all comp's have a (basic) BIOS to report tat. In case of a file (stream) it is possible to detect an EOF - (WITHOUT having to read first) by using ftell()/fseek(). Ayway it may impose some overhead. Nevertheless the code below will allways report EOF without reading (ex. is with a zero len file). Try it urself ! $handle = fopen('test', 'w'); // create a zero length file fclose($handle); $handle = fopen('test', 'r'); // re-open do { // start - EOF routine $curpos = ftell($handle); fseek($handle, 0, SEEK_END); $endpos = ftell($handle); // test wether the current pos is the last pos (=eof) if ($endpos == $curpos) { echo " ..EOF"; break; } fseek($handle, $curpos); // not EOF - return to last file pos // end - EOF routine echo "\r\nRead at " . $curpos; $buffer = fgets($handle, 9); } while(true); echo " ..END"; fclose($handle); Previous Comments: ------------------------------------------------------------------------ [2005-12-01 19:04:13] tony2001@php.net And how do you propose to distinguish "slow input" from "no input"? Where exactly there should be EOF in a *stream*? ------------------------------------------------------------------------ [2005-12-01 18:58:29] dsp at tdcspace dot dk Better explain that the loop waits for a keyboard input despite there is no input. ------------------------------------------------------------------------ [2005-12-01 18:47:38] dsp at tdcspace dot dk Description: ------------ In a continous loop for processing data with options for entering a process char (like 'q' for quit, etc.) - the feof() does not report no input (EOF) from STDIN (keyboard). note: This is about the CLI version example: the loop should output ....<keypress char>....etc do { if ( !feof(STDIN) ) { $x = fgetc(STDIN); echo $x; } echo '.'; } while(true); THE PHP MANUAL SAYS ------------------------- feof (PHP 3, PHP 4, PHP 5) feof -- Tests for end-of-file on a file pointer Description bool feof ( resource handle ) Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE. ----------------------------------------------- Apparantly "Tests for end-of-file on a file pointer" does not TEST for anything !! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35507&edit=1

« previous php.bugs (#89600) next »