note 92341 deleted from function.stream-get-line by danbrown

From: Date: Mon, 24 Jan 2011 21:28:53 +0000
Subject: note 92341 deleted from function.stream-get-line by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176261@lists.php.net to get a copy of this message
Note Submitter: bens at effortlessis dot com ---- I've seen posts here and at fgets about stream_get_line() being much faster than fgets. I'm seeing opposite results. With PHP 5.2.9 (Fedora Core 10) on a dual-core laptop with 2 GB of RAM: // SCRIPT: $fp=fopen("php://stdin","r"); // uncomment ONE of the following two lines: // while($line=stream_get_line($fp,65535,"\n")) // while ($line = fgets($fp, 65535)) { 1; } fclose($fp); // SHELL PROMPT: $ time yes "This is a test line" | head -1000000 | php -q SCRIPT with stream_get_line() enabled, it takes 25 seconds to run. With fgets enabled, it takes 10. I tried it several times and got consistent results within about 1/10 of a second. And stream_get_line() not only doesn't return the limiter (providing no sure way to pass data through including the delimiters) but is also unavailable on PHP4 (which is still commonly used) So, as far as which is faster, YMMV.

« previous php.notes (#176261) next »