Jump to content

PHP/AJAX


Wolphie

Recommended Posts

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

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

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.