Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instant notification using php/mysql,please give me a general idea

Tags:

php

Can anybody tell how to retrieve data from database like that of Facebook's notification . my requirement i have a user table and a message table when ever a user need to send a message an entry is made in the message table with sender and recipient user id. so i need to show a new incoming message status to the recipient in real time.

like image 718
Arun Killu Avatar asked Oct 28 '25 09:10

Arun Killu


1 Answers

It's a lot like ajax, except the goal is different: more open sockets hanging and less requests versus more requests and less open sockets. The JS makes a request to the server ( 2 of them actually ) and the server doesn't respond immediately, it instead hangs and sleeps until there is actually data to send to the client in which case it returns the content immediately. The reason for having 2 open hanging requests is that once one of them times out the second one is still ready to receive notifications while the 1st one reconnects. This way there is always at least one hanging request. Could check out APE, or COMET, or "reverse ajax", or "long polling with javascript". There are benefits and disadvantages to using long polling instead of classical polling, I would suggest you look into which one better fits your scenario.

Cheers

like image 112
smassey Avatar answered Oct 30 '25 23:10

smassey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!