Sanjana Nair
Sanjana Nair

Reputation: 2785

Schedule a simple php file on Cronjob on Godaddy

I am trying to run a PHP file every 15mins from 6PM. I have set cronjob like this:

*/15 18 * * * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

can someone confirm if this script will run at 6 PM and after that every 15mins?

The server is in MST standard time. So I have set 6 PM. I want the script.php to run from 6:00 AM IST to 7:00 PM IST. So I have set 6 PM MST.

In Godaddy, the process is not happening. Is there a way to check the log if cronjob has run successfully?

Thanks!

Upvotes: 0

Views: 699

Answers (2)

Phil
Phil

Reputation: 164793

The server is in MST standard time... I want the script.php to run from 6:00 AM IST to 7:00 PM IST.

Ok, so...

  • 06:00 IST is 17:30 MST (previous day)
  • 19:00 IST is 06:30 MST (same day)

This presents two problems

  1. It crosses the midnight boundary, and
  2. The 30 min part of the offset makes it very difficult to create a repeating 15 minute pattern that starts / stops at the right time.

The easy option is to ask your hosting provider to configure your server's timezone or try and use the CRON_TZ environment variable if available (probably not with Godaddy).

CRON_TZ=Asia/Kolkata

*/15 6-18 * * * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

Otherwise, you're left with something (ugly) like this

# 5.30pm and 5.45pm
30,45 17 * * * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

# Every 15 minutes from midnight till 6am and from 6pm till midnight
*/15 0-5,18-23 * * * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

# 6am and 6.15am
0,15 6 * * * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

With this approach, you're probably going to run into issues when your server changes between standard and daylight savings time and to be honest, I don't really have an answer for that.

Upvotes: 1

user1986815
user1986815

Reputation:

This one runs from 18:00 to the end of the day... at every 15th minute past every hour from 18 through 23 on day-of-month 4 in November.

*/15 18-23 4 11 * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

and then you make a new one starting with 0:00 tonight... at every 15th minute on every day-of-month from 5 through 31 in November.

*/15 * 5-31 11 * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

And then you make another one ... at every 15th minute in December.

*/15 * * 12 * /usr/local/bin/php -q /home/ddruva/public_html/site_data/script.php

and in December you turn it into one forever ... removing the "12" with a "*"

Upvotes: 2

Related Questions