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: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

  }
  
?>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.