The question is quite simple: When it comes to touching the disk, are these two examples equal, or does scenario #2 touch the disk twice?
include '/path/to/file.php';
if (file_exists('/path/to/file.php'))
include '/path/to/file.php';
I know that scenario #1 touches the disk once. Now, as I understand it file_exists()
caches the path and whether or not the file exists. In order to clear that cache you need to call clearstatcache()
.
But does include
, et alii, also use that cache? Or is it exclusive to file_exists()
?
Just one little thing to remind: include
uses include path. file_exists
doesn't. Apart from that you are obviously looking for problems instead of solutions (which must not be wrong, just saying, my answer might not fulfill what you look for, covers only a fragment).
Both of these examples touch the disk twice – reading the directory and then reading the file. In the first example, this both happens during one command, the second command splits them. It’s very unlikely that the include() will read the directory again, as your OS should contain some sort of HD cache, that should last at least this long.
But you are obviously trying to over-optimize something. Unless you are going to this >100 times in your script, there will not be any performance-difference whatsoever between your two options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With