Cronjob that updates cached file and takes about 1.5 minutes


Sep 25, 2016
cPanel Access Level
Website Owner

In my site and using cpanel, I have several cronjobs that run several php files.
Each of these php file, creates a cached file (the very first time it runs or there is no cached file)
and the next times, it updates the existing cached file with new values.

All cronjobs are working well, but I am having an isuue with one of them.
This cronjob I am talking about, takes about 1.5 minuts to update the cached file because it gets the new values from different sources and takes about 2.5 seconds for each of the 30 sources.
It does everything accordingly and the update is perfect but the isuue is...

If by coincidence, anyone requests that webpage during the update process, then he has to wait a long time (up to 1.5 minutes) before the results are displayed.
The problem is that the cached file is deleted and then replaced by tha updated cached file, but only after all the values have been collected.
Of course I get lots of complaints for this borring delay and I have been wondering all possible solutions for this.

The solution that looks the esasiest one, would be this one:
- the cached file stays in use while it is beeing updated by means of a temp cache file.
- after this temp file is complete with all the new updated values, then it replaces the current cached file.

Is this possible?

Thanks in advance.


Staff member
Apr 11, 2011

You may receive more user-feedback to this type of question via a third-party resource such as StackOverflow, as it seems to relate more to the coding of the script as opposed to a cPanel/WHM feature.

Thank you.