note 30894 deleted from function.file-get-contents by vincent
| From: | vincent@php.net | Date: | Sat, 16 Aug 2003 12:01:04 +0000 |
| Subject: | note 30894 deleted from function.file-get-contents by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54331@lists.php.net to get a copy of this message | ||
Note Submitter: dynom <a> dynom * nl
----
Speed depends on the file size and the function.
<?
function fopen_() {
$template_file = "file.php";
$fd = @fopen($template_file, "r");
$template_raw = "";
if ($fd) {
while (!feof($fd)) { $template_raw .= fgets($fd, 512); }
fclose ($fd);
return $template_raw;
}
}
function file_() {
$template_file = "file.php";
$template_raw = "";
if (file_exists($template_file)) {
return implode('',file($template_file));
}
}
?>
The file I use in these functions is smaller than 1k.
In this example file_() is faster then fopen_().
Runnig a benchmark with these functions resulted in:
file_() took me: 0.069 seconds running: 200x50 times
fopen_() took me: 0.152 seconds running: 200x50 times
ofcourse the time differs every time the script runs, but 8/10 times file_() beats fopen_().
So think about what you want with your script.
fopen() is not! alway's faster than file().