Jump to content

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.