note 92341 added to function.stream-get-line
| From: | bens at effortlessis dot com | Date: | Mon, 20 Jul 2009 17:36:17 +0000 |
| Subject: | note 92341 added to function.stream-get-line | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158515@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 64.71.164.2
Probable Submitter: 76.193.72.245
----
Manual Page -- http://www.php.net/manual/en/function.stream-get-line.php
Edit -- https://master.php.net/note/edit/92341
Del: integrated -- https://master.php.net/note/delete/92341/integrated
Del: useless -- https://master.php.net/note/delete/92341/useless
Del: bad code -- https://master.php.net/note/delete/92341/bad+code
Del: spam -- https://master.php.net/note/delete/92341/spam
Del: non-english -- https://master.php.net/note/delete/92341/non-english
Del: in docs -- https://master.php.net/note/delete/92341/in+docs
Del: other reasons-- https://master.php.net/note/delete/92341
Reject -- https://master.php.net/note/reject/92341
Search -- https://master.php.net/manage/user-notes.php