note 97668 deleted from function.fgets by danbrown

From: Date: Sun, 02 May 2010 22:41:08 +0000
Subject: note 97668 deleted from function.fgets by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168873@lists.php.net to get a copy of this message
Note Submitter: gurdiga ---- Regarding "For large files, consider using stream_get_line rather than fgets - it can make a significant difference.", I've run a couple of tests with the command lines given as examples and, yes, in that specific case fgets is slower. But, when I've removed the line length (the second argument) from fgets call, the code got even faster than stream_get_line. Here are my results: $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=stream_get_line($fp,65535,"\n")) { 1; } fclose($fp);' real 0m0.654s user 0m0.637s sys 0m0.062s $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=fgets($fp,65535)) { 1; } fclose($fp);' real 0m6.134s user 0m6.108s sys 0m0.051s $ time yes "This is a test line" | head -1000000 | php -r '$fp=fopen("php://stdin","r"); while($line=fgets($fp)) { 1; } fclose($fp);' real 0m0.408s user 0m0.411s sys 0m0.048s Nice! :)

« previous php.notes (#168873) next »