faster fopen or file_get_contents?

前端 未结 2 1994
太阳男子
太阳男子 2021-02-14 03:41

i am running multiple websites with high traffic , as a requirement , all images are downloaded via image.php?id=IMAGE_ID_HERE . If you ever done that before , you

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 04:07

    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!

提交回复
热议问题