is_file/file_exists performance and cache

后端 未结 3 1053
野的像风
野的像风 2021-02-09 09:21

I made some tests to compare and measure speed of both functions. is_file seems to be several times faster (I used 10000 iterations for both) than file_

3条回答
  •  攒了一身酷
    2021-02-09 10:18

    PHP caches both is_file() and file_exists() in the stat cache. Call clearstatcache() to clear it.

    Edit:
    If anything, the two should take similar amounts of time because they both call the OS's stat() function, but the results of one may be cached for the other by PHP (unless you clearstatcache()) or by the OS as Yuliy mentions below.

提交回复
热议问题