php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29990 Unbuffered fgets or fgetc function.
Submitted: 2004-09-05 23:49 UTC Modified: 2013-10-29 08:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: louis at mulliemedia dot com Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS: Fedora
Private report: No CVE-ID: None
 [2004-09-05 23:49 UTC] louis at mulliemedia dot com
Description:
------------
Hello,

First of all I'd like to thank all of you PHP community for your commitment to PHP. This is what makes PHP the best web scripting language on earth. If I could code this function in C, I would, however at this moment I am only a begginner in C/C++ thats why I am posting here :)

Some applications (in my case, a socket server) wich have to be run from the command line and will run forever, need to have some administration functions from the CLI so that you can create basic functions (like shutdown, etc.)

I think that an unbuffered fgetc or fegts function would be very nice so that we can read from php://stdin only if there is something to read, and so that it doesnt hang there waiting for input.

I'd like to give a few urls of other people in need of this, as I might not have explained properly :
http://lists.nyphp.org/pipermail/talk/2003-September/005595.html
http://www.phpbuilder.com/lists/php-developer-list/2001121/1771.php

Thanks,

Louis

Reproduce code:
---------------
	function getStdI() {
	
	    static $pStdn;
	    
	    if(!$pStdn)
	    {
	        $pStdn = fopen("php://stdin", "r");
	    }

	    	return trim(fgets($pStdn, 1024));
	}

while(1) {
 getStdI(); // will hang there until enter is pressed
 // socket server code
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-29 08:11 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: krakjoe
 [2013-10-29 08:11 UTC] krakjoe@php.net
This has nothing to do with being buffered or un-buffered. 

You are reading from a blocking stream; if you do not wish to block waiting for input them stream_set_blocking false on the handle.

Closing the request.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC