note 67555 modified in function.stream-get-line by curt
| From: | curt@php.net | Date: | Thu, 15 Jun 2006 04:40:12 +0000 |
| Subject: | note 67555 modified in function.stream-get-line by curt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114286@lists.php.net to get a copy of this message | ||
My testing has found this function to be dramatically faster than fgets on PHP 5.1.14. The
difference is probably due to how buffering is used internally. Compare the following:
<?php
// reads 10,000 lines in 27 seconds
while (!feof($handle)) {
$line = fgets($handle, 1000000);
}
?>
vs.
<?php
// reads 10,000 lines in 0.5 seconds
while (!feof($handle)) {
$line = stream_get_line($handle, 1000000, "\n");
}
?>
--was--
My testing has found this function to be dramatically faster than fgets on PHP 5.1.14. The
difference is probably due to how buffering is used internally. Compare the following:
<?php
// reads 10,000 lines in 27 seconds
while (!feof($handle)) {
$line = fgets($handle, 1000000);
}
?>
vs.
<?php
// reads 10,000 lines in 0.5 seconds
while (!feof($handle)) {
$line = stream_get_line($handle, 1000000, "\\n");
}
?>
http://php.net/manual/en/function.stream-get-line.php