-2

I'm trying to run a .php script on at 12 am (midnight) for every timezone.

My goal: I have a field in my database called time_zone. i need to send an email to that user in that "time zone" at 12 am.

i looked into cron jobs but i don't think it works well with timezones. is there any other way to achieve this?

EDIT: I did think about running the script every 30 min because some timezones are 30 min apart but that doesn't seem like a good solution because i wouldn't know how to calculate in which time zone it is 12:00 am.

Jason Bale
  • 363
  • 2
  • 7
  • 14
  • 2
    If you want to run it at midnight in every timezone, then you should just run it once every hour since it's always midnight in some timezone. – ebraley Jul 07 '17 at 17:08
  • 2
    You need to give more information. Is the script running centrally on a server, or is it running locally on a number of machines that need to identify their own time zones? – Arya McCarthy Jul 07 '17 at 17:09
  • @ebraley and also on some half-hours and quarter-hours. https://en.m.wikipedia.org/wiki/List_of_UTC_time_offsets – Arya McCarthy Jul 07 '17 at 17:09
  • the script will be run on one server – Jason Bale Jul 07 '17 at 17:11
  • 1
    Why do you need to know which timezone is 12am? What does the script do? Perhaps you should share a little more about what do you intend to do. – Terry Jul 07 '17 at 17:14
  • @Terry edited the post – Jason Bale Jul 07 '17 at 17:16
  • It's a lot like [this question](https://stackoverflow.com/questions/44961104/run-cron-job-at-12-am-in-every-time-zone) from yesterday. How about the suggestion from [this comment on that question](https://stackoverflow.com/questions/44961104/run-cron-job-at-12-am-in-every-time-zone#comment76897916_44961104)? – Don't Panic Jul 07 '17 at 17:18
  • @Don'tPanic does that bump it? – Jason Bale Jul 07 '17 at 17:19
  • Sorry, not sure what you mean. – Don't Panic Jul 07 '17 at 17:20
  • @Don'tPanic well if i comment on an old question, how does that make it appear at the top where people can see it? – Jason Bale Jul 07 '17 at 17:24
  • No, commenting on it won't make it appear at the top again. – Don't Panic Jul 07 '17 at 17:26
  • @Don'tPanic ok, sorry im new to this but how would the question get attention so people can try to answer? – Jason Bale Jul 07 '17 at 17:41
  • @JasonBale see https://stackoverflow.com/help/no-one-answers, https://meta.stackoverflow.com/questions/266338/how-can-i-improve-my-questions-or-how-to-get-more-attention-for-my-questions ,and https://meta.stackexchange.com/questions/7046/getting-attention-for-unanswered-questions – Don't Panic Jul 07 '17 at 18:04

1 Answers1

1

You could make an array of all time-zones and compare from that. If that exists in the array you can send the email. It's not perfect, but it should do the job.

usmany
  • 146
  • 2
  • 11
  • how so? example? – Jason Bale Jul 07 '17 at 17:21
  • $array = array('TZ_1', 'TZ_2', 'TZ_3', ...) foreach($timezone in $array){ $cur_time = time() // get current time with required format If array contains the $timezone send the email } – usmany Jul 07 '17 at 17:23
  • but how would you calculate the time? for example, how would you see which time zone is 12:00 am so i can run the script? – Jason Bale Jul 07 '17 at 17:25
  • php is a server side language... so when you'll request a page, it'll show that. One way is that you could make a page, and do an AJAX call on it, and as long as the page is there,, the ajax call will continuously check the time by above logic and send email from there. – usmany Jul 07 '17 at 17:26
  • https://stackoverflow.com/questions/26980282/time-trigger-database-updating – usmany Jul 07 '17 at 17:29