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

后端 未结 19 1108
迷失自我
迷失自我 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:36

    Use absolute paths! Depending on your include_path setting PHP checks all(!) these dirs if you check relative file paths! You might unset include_path temporarily before checking the existence.

    realpath() does the same but I don't know if it is faster.

    But file access I/O is always slow. A hard disk access IS slower than calculating something in the processor, normally.

提交回复
热议问题