Hi, thanks for jumping-in! Every clue is a potential solution!
That's correct; the filesystem is mounted. I assume that the authentication is performed once upon mounting and perhaps periodically thereafter (but not on every filesystem request). The mounting happens via fstab using a "sshfs" entry that leverages public key authentication.
I should have mentioned that I did try calling clearstatcache() just before making each call to file_exists(). Surprisingly, this doubles the execution time for file_exists() when the file does not exist, but doesn't affect the time required when the file does exist.
Without the calls to clearstatcache() - files do not exist:
Checking for file "/ndtcat/dev/back-1/mp3/2885.mp3...
Check required 4.377338886261 seconds
Checking for file "/ndtcat/dev/back-1/flac/2885.flac...
Check required 4.3129899501801 seconds
Checking for file "/ndtcat/dev/back-1/mp3/2886.mp3...
Check required 4.2456741333008 seconds
Checking for file "/ndtcat/dev/back-1/flac/2886.flac...
Check required 4.2454588413239 seconds
Checking for file "/ndtcat/dev/back-1/mp3/2887.mp3...
Check required 4.3836197853088 seconds
Checking for file "/ndtcat/dev/back-1/flac/2887.flac...
Check required 4.2531359195709 seconds
With the calls to clearstatcache() - files do not exist:
Checking for file "/ndtcat/dev/back-1/mp3/2885.mp3...
Check required 8.5778198242188 seconds
Checking for file "/ndtcat/dev/back-1/flac/2885.flac...
Check required 8.5042169094086 seconds
Checking for file "/ndtcat/dev/back-1/mp3/2886.mp3...
Check required 8.5915818214417 seconds
Checking for file "/ndtcat/dev/back-1/flac/2886.flac...
Check required 8.4928848743439 seconds
Checking for file "/ndtcat/dev/back-1/mp3/2887.mp3...
Check required 8.4456911087036 seconds
Checking for file "/ndtcat/dev/back-1/flac/2887.flac...
Check required 8.5748710632324 seconds
Without the calls to clearstatcache() - files do exist:
Checking for file "/ndtcat/dev/back-1/mp3/6094.mp3...
Check required 0.0017569065093994 seconds
Checking for file "/ndtcat/dev/back-1/flac/6094.flac...
Check required 0.0017290115356445 seconds
Checking for file "/ndtcat/dev/back-1/mp3/6095.mp3...
Check required 0.00187087059021 seconds
Checking for file "/ndtcat/dev/back-1/flac/6095.flac...
Check required 0.0017759799957275 seconds
Checking for file "/ndtcat/dev/back-1/mp3/6096.mp3...
Check required 0.0018107891082764 seconds
Checking for file "/ndtcat/dev/back-1/flac/6096.flac...
Check required 0.0018069744110107 seconds
With the calls to clearstatcache() - files do exist:
Checking for file "/ndtcat/dev/back-1/mp3/6094.mp3...
Check required 0.0018830299377441 seconds
Checking for file "/ndtcat/dev/back-1/flac/6094.flac...
Check required 0.001823902130127 seconds
Checking for file "/ndtcat/dev/back-1/mp3/6095.mp3...
Check required 0.0018379688262939 seconds
Checking for file "/ndtcat/dev/back-1/flac/6095.flac...
Check required 0.0018370151519775 seconds
Checking for file "/ndtcat/dev/back-1/mp3/6096.mp3...
Check required 0.0017740726470947 seconds
Checking for file "/ndtcat/dev/back-1/flac/6096.flac...
Check required 0.0017499923706055 seconds
Any thought as to why calling clearstatcache() makes each check take twice as long for non-existent files?
What I find strange is that I can scandir() the directory in which I am checking for the file, and the results come back immediately. There are hundreds of files in this directory. Is it just me, or does it make zero sense to be able to list the entire directory contents in a fraction of a second, but require 4+ seconds to check for the existence of a single file within it?
Also, as mentioned in my OP, the operating system is able to determine more or less instantly that the file doesn't exist (tested by calling "stat /path/to/file" on the terminal). Why does PHP take so much longer, especially if it is leveraging the OS's stat function?
When I execute my test script, and then check jnettop, I can see "light network activity" -- exactly 4.75KB/s -- between the local server and the remote server that contains the files for whose existence I am checking. I find it strange that when I run my test script this connection always ramps-up to 4.75KB/s within a few seconds and remains at 4.75KB/s for the duration of the calls to file_exists(). It's strange that a) this connection is "capped" at 4.75KB/s, yet I am able to copy binary data from the same remote server (in the same script) at over 3MB/s; and b) that 4.75KB/s for ~25 seconds would actually be required simply to determine if a file exists.
Another observation: if I change the call from file_exists() to is_file(), filesize(), etc., the function execution times are the same. 4+ seconds apiece.
I really hate to have to call "stat" on the command-line to resolve this. Just hate to.
Any other thoughts?
Thanks again!