A facebook-like-notification system in php

18,132

Solution 1

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.

Solution 2

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.

Share:
18,132
Zakaria
Author by

Zakaria

Updated on July 25, 2022

Comments

  • Zakaria
    Zakaria almost 2 years

    How can I put in place a facebook-like-notification system: - A userA writes a message to the userB - A listener on the database routes the message to the userB - On the userB interface, the message appears instantly

    How can I do that in php?

    Thank you very much,

    Regards

  • Alec Smart
    Alec Smart over 13 years
    This is a horrible idea. PHP is not geared towards long polling.