diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-07-31 11:51:18 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-07-31 11:51:18 -0700 |
commit | a8bb0462097bd83cd87bf9048b8be879cff3cd6c (patch) | |
tree | 9672bb518d697f565e6e6f5861da74a94863d094 /modules/gallery/controllers | |
parent | 7b8ed1079624eefae8d83fac89caa0eaa3fc9ef4 (diff) |
Use readfile() instead of fopen()/fpassthru()/fclose() for brevity.
I've done some tests on a 60M flv and found that there's no difference
in memory consumption with these three approaches:
public function test() {
Kohana::close_buffers(false);
$file = "/home/bharat/basketball.flv";
if ($fd = fopen($file, "rb")) {
while (true) {
$bits = fread($fd, 65535);
if (strlen($bits) == 0) {
break;
}
print $bits;
set_time_limit(30);
}
fclose($fd);
}
Kohana_Log::add("error","test: " . print_r(array(memory_get_peak_usage(true),memory_get_peak_usage(false)),1));
}
public function test2() {
Kohana::close_buffers(false);
$file = "/home/bharat/basketball.flv";
$fd = fopen($file, "rb");
fpassthru($fd);
fclose($fd);
Kohana_Log::add("error","test2: " . print_r(array(memory_get_peak_usage(true),memory_get_peak_usage(false)),1));
}
public function test3() {
Kohana::close_buffers(false);
$file = "/home/bharat/basketball.flv";
readfile($file);
Kohana_Log::add("error","test3: " . print_r(array(memory_get_peak_usage(true),memory_get_peak_usage(false)),1));
}
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r-- | modules/gallery/controllers/file_proxy.php | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index bead9f3f..15b4279f 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -72,8 +72,8 @@ class File_Proxy_Controller extends Controller { // necessary, it's easily resurrected. // If we're looking for a .jpg then it's it's possible that we're requesting the thumbnail - // for a movie. In that case, the .flv, .mp4 or .m4v file would have been converted to a .jpg. - // So try some alternate types: + // for a movie. In that case, the .flv, .mp4 or .m4v file would have been converted to a + // .jpg. So try some alternate types: if (preg_match('/.jpg$/', $path)) { foreach (array("flv", "mp4", "m4v") as $ext) { $movie_path = preg_replace('/.jpg$/', ".$ext", $encoded_path); @@ -131,10 +131,7 @@ class File_Proxy_Controller extends Controller { } else { header("Content-Type: $item->mime_type"); } - Kohana::close_buffers(false); - $fd = fopen($file, "rb"); - fpassthru($fd); - fclose($fd); + readfile($file); } } |