faster fopen or file_get_contents?

对着背影说爱祢 提交于 2019-12-04 01:29:06

fopen and file_get_contents are nearly equivalent

to speed up with consistence the page load you can use

http://www.php.net/fpassthru

or, even better

http://www.php.net/readfile

with those functions, content of file is printed directly, byte per byte

as opposed to file_get_contents, for example, where you store the whole data inside a variable

$var = file_get_contents();

so, to make these work correctly you will need to disable output buffering (otherwise it would make readfile() pointless) in the page that serves the images

hope this helps!

Why dont you cache the image content with apc ?

if(!apc_exists('img_'.$id)){
    apc_store('img_'.$id,file_get_content(...));
}

echo apc_fetch('img_'.$id);

this way image content will not be read from your disk more than once.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!