Does () use the cache file_exists ()?

The question is quite simple: when it comes to touching the disk, are these two examples equal or is scenario 2 touching the disk twice?

Scenario number 1

include '/path/to/file.php'; 

Scenario number 2

 if (file_exists('/path/to/file.php')) include '/path/to/file.php'; 

I know that scenario number 1 touches the disk once. Now, as I understand it, file_exists() caches the path and whether the file exists. To clear this cache, you need to call clearstatcache() .

But does it use include , etc. is this cache? Or is it exclusive to file_exists() ?

+6
source share
2 answers

Both of these examples touch the disk twice — reading the directory, and then reading the file. In the first example, this happens during one command, the second command separates them. It is very unlikely that include () will read the directory again, since your OS must contain some kind of HD cache that should last at least so long.

But you are obviously trying to overestimate something. If you don't do this> 100 times in your script, there will be no performance difference between your two options.

+3
source

Just one little thing to remind: include uses include path. file_exists no. In addition, you are clearly looking for problems instead of solutions (which should not be wrong, just saying my answer may not match what you are looking for, covers only a fragment).

+5
source

All Articles