A facebook-like-notification system in php A facebook-like-notification system in php database database

A facebook-like-notification system in php


I wouldn't advise using either polling or trying to implement a push based solution using PHP, if you are going to have any sizable traffic. What happens is that eventually all the PHP processes get blocked, and then you can't serve anymore web requests.

Look into node.js, cometd or another push based solution. If you need something simple and need to get up and running quickly, I'd recommend http://pusherapp.com/. They have a PHP client available and super simple API.


I have a system that works well set in place. It basically has the set up like this:

notification_id
user_id
module
action_type
added_by
read
read_date
added

This is a simple way of doing it. user_id is who it's for, added_by is the user id of whomever performed the action. Module is where it was performed at, and action_type is what happened (comment, deletion, added, etc). Read is if it's already been viewed, and read_date is when it was viewed.

I then have a class that builds the verbiage based on what the values above are.

I have then set up a crontab that will clean up old notifications in the database after so many days.


You could do this one of two ways. In PHP the easiest way would be 'polling'. The newer neater method is using HTTP Push with a Comet server; but that's not so great for PHP.

To use polling ou simply update a table in the database with UserA's message flagged as to-be delivered to user b. You have a script running every few seconds via ajax that polls the database for the message on userb's client. If the message is there you populate it. This is very inefficient.