views:

57

answers:

1

Hi all

I'm trying to watch for a file being modified in a long running php script. The basic algorithm is this:

...
$mtime = filemtime($filename);
sleep($delay);
if($mtime < filemtime($filename)) 
     ... // do something because file was changed elsewhere

Problem is filemtime returns the same value withing same script, e.g. if a script runs for say 10 minutes it will always get the same modification time regardless to actual changes done to the file within the same script or by other means.

Please help with an advice on how to actually get the latest modification time?

+2  A: 

Take a look at http://php.net/clearstatcache:

When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information.

edit: Do you want this to run for a specific operating system? Then there would be other notification possibilities (maybe requiring something else than php).

VolkerK
Yes, calling `clearstatcache()` does the trick, many thanks.
zzandy