love_php Posted June 30, 2010 Share Posted June 30, 2010 Hi, I am trying to implement the basic calendar for different people living in different timezones. They can add events for a particular date and time (which would be according to their timezone) in their calendar.I want to send notification email to them for that event that will occur.Now my server timezone will be different, so i am planning to convert the time(that the users will enter in their timezone) to standard timezone (i.e timezone of my server or GMT) while updating the events,date and time to my database. For this, should i use cron job,scheduled ( every minute) to run a script which would check what events occur at that time and send a notification ? I have hashed a sample code as below. <?php $con = mysql_connect("localhost","root","");[i] //Connection to the database[/i] if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("cal", $con); $date = date('jS F Y h:i A'); [i]// Taking GMT here, will be saving it in GMT too.[/i] $result = mysql_querymysql_query("SELECT * FROM users WHERE eventtime= $date"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $to = $row["emailid"]; [i] //Sending Email[/i] $subject = 'Event Notification'; $message = $row["event"]; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206266-making-calendar-scheduling-events-help-needed-to-optimize-the-code/ Share on other sites More sharing options...
phpology Posted June 30, 2010 Share Posted June 30, 2010 Dont see it being an issue to be honest but you should think about adding an error tracker maybe, in case it fails or your script breaks with malformed email addresses (make sure its a valid format when they save an event). Actually increase your script time out in case you are sending out loads of emails during that time frame. set_time_limit() something to think about - make sure you index your datetime column too so you get faster data retrieval Quote Link to comment https://forums.phpfreaks.com/topic/206266-making-calendar-scheduling-events-help-needed-to-optimize-the-code/#findComment-1079172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.