I have a caching class that has a flat file driver, meaning you can cache arbitrary data to a flat file using a key and expiration time, then retrieve this data using the same key.
Expire duration must be set with the setCache method in order to work with other drivers (as opposed to having an expiration duration argument on the getCache method, even though this would make determining whether the cache has expired much easier, as I could just compare it to the files last modification time).
Currently I prepend a timestamp (+ expire duration) to the beginning of the file. When a user tries to getCache related to that file, the method opens the file and strips off the first line to get this timestamp. It then uses that timestamp to figure out whether or not that cache has expired. This is not very efficient obviously.
I recently came accross a PHP function touch(), which allows me to set a file’s last modification time to an arbitrary value. This sounds awesome because it would allow me to (instead of the above mentioned method of figuring out if the cache has expired), set the file’s last modification time to some point in the future. I can then check this time to see if the cache has expired yet.
I really REALLY want to be able to use this. My application is distributed however, and since this function works with the environment, I am not sure if I should trust this function to work as expected accross the board on different systems. Does anyone have any information or resources about the compatability of this function?
The biggest issue you are going to run into here is permissions. If the user your php script (actually its apache) creates the file, he will own the file and be able to make changes as desired. This will only work assuming that the apache user has the permissions to create that file inside the folder ( check the directory permissions).
You can also create the file your self and set the owner to be the user that apache runs php scripts as (can be found in the httpd.conf file)
https://www.php.net/manual/en/function.touch.php — documentation for touch
http://drupal.org/node/34023 –describes the exact situation you are running into and goes more into permissions.
http://www.faqs.org/docs/securing/chap29sec245.html — talks about modifying the httpd.conf file