Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to implement a push notification systems

We would like to make a realtime price change system to be able to see difference with competitor prices against our product prices.

We have no experience with Push notification / COMET system by Javascript and PHP. If you don't mind, I would like to get your experiences, suggestions about this technique. So here are my questions:

  • What is the best way doing like that system?
  • We are experienced PHP developers, so is PHP appropiate for this task?
  • If you know any project or solution ( open source or commercial ) that is able to do this, could you please share?
like image 336
Oğuz Çelikdemir Avatar asked Oct 21 '22 20:10

Oğuz Çelikdemir


1 Answers

  1. Here is the approach that we use. Javascript sends regular AJAX request to PHP file. PHP file makes database query and if noting found, just sleeps for 0.5 second (or 1 second), then makes database query again. If 30 second passed and still nothing new found in database (this is needed for giving output, before HTTP timeout occurs), then it outputs something (like noting found). Javascript starts another query immediately after it received output from the last query. Javascript always keeping track of last ID of the database table which comet is monitoring. This is used to query only database rows that is greater than last ID that we have seen.
  2. Yes PHP is appropriate. Just remember one important thing! You need to close any sessions that are open before entering in comet loop. PHP uses session locking to prevent two threads writing into same session simultaneously. If you forget to close session all other threads will be locked (like browsing through website will be impossible).
  3. I can advice open source PHP framework that we use. It called Stingle. It has solid and production ready Comet plugin.
like image 86
Alex Amiryan Avatar answered Oct 24 '22 12:10

Alex Amiryan