jmcc Posted April 5, 2011 Share Posted April 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232741-check-db-for-new-entry-and-alert-user/ Share on other sites More sharing options...
RussellReal Posted April 5, 2011 Share Posted April 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232741-check-db-for-new-entry-and-alert-user/#findComment-1197120 Share on other sites More sharing options...
jmcc Posted April 5, 2011 Author Share Posted April 5, 2011 Great thanks, will give it a shot. Quote Link to comment https://forums.phpfreaks.com/topic/232741-check-db-for-new-entry-and-alert-user/#findComment-1197121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.