Jump to content

Check DB for new entry and alert user


jmcc

Recommended Posts

Hi

 

I have a live chat integrated into my website that uses Ajax, PHP and MySQL.

 

When two people have the chat window open they can chat and it works fine.

 

How can I send an alert to the person being requested to chat with, or for the chat.php page to popup automatically.

 

It prob needs to be some function constantly running in the background check the DB for new message entries.

 

Thanks

Jay

Link to comment
https://forums.phpfreaks.com/topic/232741-check-db-for-new-entry-and-alert-user/
Share on other sites

longpolling #1 BEST answer to this, but server limitations and browser limitations mess you up :)

 

for example, google chrome only allows 2 or 3 live connections at a time, which means if they have 3 or 4 instances of your web app, one of those will be inactive until it can secure a slot to start a connection.

 

server limitations vary but its mostly because servers offer limited connections at the same time..

 

an example of a longpoll is simply:

 

1. request a php file from your server (longpoll.php) with javascript and wait for a return

 

2. in longpoll.php you will throw yourself into an infinite loop, everytime the loop LOOPS you will check the database for new results, messages, etc. IF and WHEN you get a return from the database, you will return it to the browser..

 

3. browser will get back data or the connection will time out, handle the data you've just received, be it a new message or a friend coming online etc.

 

4. repeat steps 1-3 immediately

 

this will get your live chat on the right track :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.