I have a caching system in php that stores mysql query results in xml. I lock the cache on creation by creating a lock file with an exclusive write descriptor, and then delete it as soon as the cache file completes.
However, there are times when the script either crashes or stops the average execution, leaving the lock file in place, doing any further execution of the script, assuming that the cache is always updated.
I tried to verify that the file has several minutes and is trying to get exclusive write access to the file in order to update the lock and start execution, however, it looks like the file is still open with the previous descriptor and I cannot open a new descriptor to guarantee that the current process is the only one with file access and deletion.
Is there a way to ensure that if the script is stopped in the middle of execution, all open file descriptors are closed and the files are available for future processes to access?
thanks
source
share