大网数据广告活动
网站运营与故障问答

Why is the php.ini timezone setting is not used to determine when a PHP cron job runs?

· 52CE 我爱测

I use shared hosting at Bluehost and changed the default date.timezone to UTC in my php.ini . Everything works fine with my PHP script and date() return the UTC time as expected. The problem occurs with the crontab, because when …

问题原文

原帖链接 · Florent · CC BY-SA 3.0

I use shared hosting at Bluehost and changed the default date.timezone to UTC in my php.ini. Everything works fine with my PHP script and date() return the UTC time as expected.

The problem occurs with the crontab, because when I enter a cron job to be executed every Monday at 00:15 AM UTC with the following line :

15  0   *   *   1   php /home2/mywebsite/public_html/php/myscript.php

Then the script is not executed at 00:15 AM UTC time but at 00:15 AM UTC-6 which is Western America I guess. For this reason I need to set it at 06:15 PM of the day before, which is Sunday, to have it executed at Monday at 00:15 AM UTC:

15  18  *   *   0   php /home2/mywebsite/public_html/php/myscript.php

I asked their support but they said they cannot help with the crontab. For them it just work.

Is it related to the shared hosting and is there a possibility to change this so that crontab service use my php.ini timezone setting ?

已采纳解答

原帖链接 · Florent · CC BY-SA 3.0

I've found that after I changed my php.ini timezone setting to UTC the Bluehost shared hosting cron service was still using the MDT (Mountain Daylight Time) timezone which has an offset of -6 hours. This is probably due to the shared hosting as stated by @dan in the comments, and there is nothing to change that but to switch to a dedicated hosting.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。