0

I have a php file which works fine in browser as well as in cron job section. The only thing i am facing is the timezone which i want to run that cron is not syncing with the server timezone.

I want to run the cron job in indian timezone everyday morning @ 7 am. But cron is not running @ 7 am instead it runs in some other time which am unable to identify since it vary each time it runs.I am using Godaddy Hosting services. Any help appreciated.

Durgaprasad
  • 323
  • 2
  • 14

1 Answers1

0

you can run cronjob every hour, and check if current hour is 7am of Indian time zone :)

<?php
$time = new DateTime();
$time->setTimezone(new DateTimeZone("Asia/Calcutta"));

if( $time->format("H") == 7 ) {

    // RUN

}
MrSmile
  • 1,217
  • 2
  • 12
  • 20
  • Thanks for the reply @Chudilka. But i am using the default Cron job option which is in my Cpanel and selecting the time over there with command "wget myurl.php". Also I am not sure whether the cron job can be initiated through PHP code after checking the desired time as you suggested. – Durgaprasad Jun 26 '18 at 12:23
  • I suggested add selected code in your PHP-code, that you call with wget command. Absolutely, it won't work if you call wget of non-your script (some remote URL). – MrSmile Jun 26 '18 at 12:28
  • okay my question is very simple. I am already executing the URL which is part of my website every minute from the Cpanel Cron Jobs which works fine. But when i change the time to day there is significant timezone difference between my server and the time I set which randomly changing each time it executes. so I am unable to identify in which timezone the cron jobs are executing the jobs. If i am able to identify the timezone of which my crons are executing then that will be enough for me to adjust the time in my crons – Durgaprasad Jun 26 '18 at 12:34