php - My script to deliver emails based on each user's local time -


i'm posting php script hoping opinions , advice. php application needs send individual emails users based on local time.

each user has set of time-marks @ chose receive emails. how time-marks field looks in database: 12:00:00, 14:15:00, 16:30:00.

i'm rounding time-marks nearest quarter hour , sending cronjobs every quarter hour check users scheduled email , sending respective emails one-by-one (worried :-/) in loop.

my server timezone set america/new_york can't send emails based on time because users in different locations. below developed model should handle issue.

solution:

  1. collect each user's timezone
  2. on each cronjob each user's localtime in php using timezone data
  3. create array of user's time-marks.

    example: 12:00:00, 14:15:00, 16:30:00

    array ( [0] => 12:00:00 [1] => 14:15:00 [2] => 16:30:00 )

  4. if user's localtime matches 1 of his/her time-mark send email

  5. update database date sent

php script:

    //loop through user's entries table holds content emailed         foreach ($entries $entry) {            //create array of user's time-marks set                      $timemarks_arr = array_map( "trim", str_getcsv($entry->timemarks));           //get user's localtime          $timezone = $entry->timezone; //user's time-zone          $userlocaltime = gmt_to_local($timestamp, $timezone, $daylight_saving); //gets user's localtime           //if user's time-mark matches his/her localtime                if (in_array($userlocaltime, $timemarks_arr))          {                   //send email using codeigniter's email class                  $this->email->clear(); //reset between cycles                  $this->email->from('myemail@gmail.com', 'name');                 $this->email->to($entry->email);                   $this->email->subject($entry->content);                 $this->email->message($entry->content);                   $this->email->send();                     echo $this->email->print_debugger();                                      //update date sent                 $user_id = $entry->user_id;                  $this->db->query("update `entries` set date_sent=now() `user_id` = $user_id , `entry_id` = $entry->entry_id");           }      } 

concerns:

  • is model reliable?
  • performance issues. takes 5 seconds send 4 emails.. (note: i'm sending emails testing environment on local windows server - wamp)

unless set server script server time can local time.

what write simple program in c++, or other language can update database records. have program set record server time database hour, , when users need call have them read field database. have done before , worked pretty well.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -