Jump to content

Making calendar - Scheduling Events - Help needed to optimize the code.


love_php

Recommended Posts

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: calendar@calendar.com' . "\r\n" .
    'Reply-To: calendar@calendar.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

  mail($to, $subject, $message, $headers);

  }
  
?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.