file_exists() is too slow in PHP. Can anyone suggest a faster alternative?

后端 未结 19 1065
迷失自我
迷失自我 2021-02-05 01:18

When displaying images on our website, we check if the file exists with a call to file_exists(). We fall back to a dummy image if the file was missing.

Howe

19条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 01:52

    We fall back to a dummy image if the file was missing

    If you're just interested in falling back to this dummy image, you might want to consider letting the client negotiate with the server by means of a redirect (to the dummy image) on file-not-found.

    That way you'll just have a little redirection overhead and a not-noticeable delay on the client side. At least you'll get rid of the "expensive" (which it isn't, I know) call to file_exists.

    Just a thought.

提交回复
热议问题