0

I've to add one event notification inside of the calendar of my users they all have an account of my Google Apps. The number of my users are for now 200 but it will increase to 1500. How can I add via PHP from Google Calendar API all those notifications? The secondary objective is that all the users that has the mobile configuration will also receive the sms notification. My issue is that if I launch a script now to add 200 notifications to an event that starts in 5 minutes, it will take a lot of time, so some users do not receive in time the notification.

thanks in advance!

Alberto

albertopriore
  • 614
  • 2
  • 9
  • 36

1 Answers1

3

In nutshell, spread the large set of requests into smaller set of request.
Most of the servers nowadays are multi core, it should capable to perform multitasking

Setup two scripts

Master scripts

  1. fetch the event that start in 5 minutes
  2. find all the users & details that need to be notified (assume is 200)
  3. for every 10 notifcations, spawn a shell_exec process that calling Notification script, and make sure push the calling into background (refer php execute a background process )

Notification script

  • receive the details of 10 users need to be notified (details input from master scripts)
  • process the notification

Benefits

So, instead of traditional fetch one user notify one user,
you need 200 x 1 = 200 seconds

Now, you just need

1 seconds for master + (10 x 1 seconds) = 12 seconds

Things to take note

Server & bandwidth resources is not unlimited,
there is an capped on how many processes your server can run concurrently,
this up to you to perform testing and fine-tune

Community
  • 1
  • 1
ajreal
  • 46,720
  • 11
  • 89
  • 119
  • Hi! I made what you suggested to me. But it takes more second than before. I write the script like this. But the execution of the script wait all the exec(); so it doesn't made the php in background. foreach($tests as $test) { exec("php test.php ".$test["id"]); } what I'm doing wrong? thanks in advance! – albertopriore Jan 10 '11 at 12:19
  • you should push the `exec` into background - http://stackoverflow.com/questions/45953/php-execute-a-background-process – ajreal Jan 10 '11 at 12:23
  • sorry but I continue to do not understand what exactly I've to do to push exec into background. Which of those answers in http://stackoverflow.com/questions/45953/php-execute-a-background-process are correct? – albertopriore Jan 10 '11 at 12:53
  • in short, push into background mean PHP won't not wait for exec to return result – ajreal Jan 10 '11 at 13:04
  • ok but I do not found the correct piece of code to do that. What is the correct piece of code? – albertopriore Jan 10 '11 at 14:33