2
On my website and using Cpanel, I have several cronjobs that run multiple php files. Each of these cronjobs creates a cached file where the site will pick up information. All the cronjobs are working fine, but I’m having a problem with one of them. This cronjob that I’m talking about, takes about 1.5 minutes to update the cached file because it will get values from various sources and this process is time consuming. It does everything accordingly and the upgrade is perfect, but ...
The problem is that the cached file is deleted as soon as cronjob is started and the new cache file will only appear after all values have been collected (1.5 minutes later). Therefore, if a user of the site has the misfortune to refer to the page that depends on this cache during the update process, he will eventually give up because he thinks it is not working.
I have tried solutions but unsuccessfully.
The solution that seems to me the best, would be this: - the cached file remains in use while a new cache is being created through a temporary file. - when this temporary file is completed with all new values already updated, only then it replaces the current cache file.
Can someone give me a hint on how to get this?
Seems to me it’s just flow problem anyway. If you cannot consider another caching technique (if your system is in fact dependent on this cache medium), the best solution is the one you yourself mentioned: the cache file is overwritten only when the cron task is completed. If the cache you use is simple (HTML only), consider using tools such as PHP OP Cache. If your site is in Wordpress the Wpsupercache may be a good solution.
– juniorgarcia
Not at all. I put the comment in response, since it helped you.
– juniorgarcia