Time zone cron jobs execute within, if different from server time zone
How can we make a PHP CRON script execute in a different time zone from the server time zone? We can't edit the PHP script to add code to change the time zone.
In our case, the server is in the CST time zone. We can't change the server time zone setting.
We are located in the EST time zone. We've configured our PHP web application (WHMCS) to use the EST time zone so timestamps within the application are correct.
However, there are a few PHP scripts that are scheduled to run regularly via CRON. These scripts appear to be running in the CST time zone. We can tell by the timestamps created by the scripts. Note that we are not trying to change the time WHEN the scripts run, we're trying to change the time zone for the environment where the scripts run.
Using crontab -e, I will sometimes get the following with with the jailshell lines.
So, I added TZ=America/New_York above each of the SHELL lines as shown. America/New_York is the EST time zone.
But after testing, the pop.php script still seems to run in the CST time zone.
Is there a different way I should be editing the crontab with the jailshell active?
Is there a different command I should insert instead of the TZ env var?
Or is there a different method to set the time zone for the PHP environment within a CRON task.
We're running in a "cloud account" on a web host, cPanel 86.0.34.
Linux version 4.14.121-197.ELK.el6.x86_64 (mockbuild@bambooagent4.atlassian.endurance.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)) #1 SMP Tue May 21 13:24:40 CDT 2019
-
Hey there! If the machine's timezone has been properly set, I would recommend restarting the crond service in general to see if that makes it pick up the correct time from the machine itself. I'm not seeing anything obviously wrong with the details you provided in your first post, so that would be the first thing I'd try. 0 -
The machine time zone is set via the hosting company (and is CST) and we cannot change it. How can we make a PHP CRON script execute in a different time zone from the server time zone, within the cPanel jailshell framework? Hey there! If the machine's timezone has been properly set, I would recommend restarting the crond service in general to see if that makes it pick up the correct time from the machine itself. I'm not seeing anything obviously wrong with the details you provided in your first post, so that would be the first thing I'd try.
0 -
Instead of "TZ=" can you try using this in the file CRON_TZ=America/New_York
to see if that changes the behavior?0 -
The jailshell seems to affect editing. We would use crontab -e to edit the cron script and save our changes. We could check the cron table afterwards and our changes would be there. After a certain amount of time, we'd edit crontab -e and our changes would be gone. We don't know for sure, but it seems like some feature of jailshell was re-creating our crontab script and deleting our changes. Ultimately, since these were PHP scripts, we added a config.php file to the folder that contained the scripts. The config.php contained the lines: define('TIMEZONE', 'America/New_York'); date_default_timezone_set(TIMEZONE); We don't know if the CRON_TZ would have worked or not. Setting the timezone via config file caused the scripts in the same folder to use the correct time zone. 0 -
Did that additional config file allow things to run how you expect? 0
Please sign in to leave a comment.
Comments
5 comments