Wolphie Posted April 10, 2009 Share Posted April 10, 2009 Not entirely sure which forum this should be in, although it's also a PHP issue. I'm developing a MySQL based chat room which uses AJAX to send/retrieve messages and the user list. Now, I'm faced with a dilemma. What would be the best way to go about retrieving the messages and user list? Most AJAX based chat rooms use setTimeout() with a small interval to query the PHP script every x number of milliseconds, this would cause a lot of over head. I've read somewhere about 'hanging AJAX' which basically means AJAX makes a request to a PHP script and if the PHP script has no new data, it will 'hang' there until new data is available. Now this would reduce over head dramatically, but I have no idea how to go about it. Has anybody experimented with this technique or would using setTimeout() be the best approach here? Thanks. Link to comment https://forums.phpfreaks.com/topic/153409-phpajax/ Share on other sites More sharing options...
ratcateme Posted April 10, 2009 Share Posted April 10, 2009 i haven't done to much ajax programming myself but i could see how it would work basically if your php script got the list of new users stored it in session and sent the list to the client. on next request it gets the list checks it with the one saved in session and if they are the same it calls sleep for say 1 second then checks again. now i am not sure how long it would take for the ajax request to timeout so you might have to add limit in the loop so the ajax wont time out but you probably also want to make sure that there is some kind of checking in you ajax so that if one times out then another call is made. Scott. Link to comment https://forums.phpfreaks.com/topic/153409-phpajax/#findComment-805977 Share on other sites More sharing options...
ricmetal Posted April 10, 2009 Share Posted April 10, 2009 can ajax hang on a single connection? if so, how? Link to comment https://forums.phpfreaks.com/topic/153409-phpajax/#findComment-806023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.