Jump to content

Settimeout Problem


Guest Noo
 Share

Recommended Posts

Hello everyone.Well i've been trying to make chatting program lately just to see how far can i go with the ajax.the programe works as following:Javascript --> use xmlhttprequest --> calls php file that read a text file --> then return the data and displays the data i been using settimeout every 800 ,to keep doing that loop to keep the user up-to-date the problem is that on my local serveri can use Settimeout ("chatter()",100) or even less seconds than 100 and it works but on the website i can't reduce it to less than 800 other wise it wont workim not sure whats the problem here i know that settimeout works for date on websites that means it can work on fast periods seems like the problem is with the xml or php.is there is any other way to make the program work faster (should i work with databases are they faster?) .sorry for talking too much :)and thanks alot for this amazing website :)

Link to comment
Share on other sites

HTTP requests can be slow, you need time for a response to come. 800 means 0.8 seconds. 100 is 0.1 seconds.If you're using 100, that means you're sending 10 requests per second, the internet is not that fast, and it also may be stressful for the server.

Link to comment
Share on other sites

I'm not sure about other browsers, but IE at least has a 2 connection limit to any one server. A connection includes a request for a single web page, an image, a CSS or Javascript file, etc. You're telling the browser to send at least 1 request per second, looking for data, so if the requests take longer than 800ms to finish, the queue is going to get backed up and never finish, eventually the browser will just grind to a halt when it has a pending queue of several hundred requests. You might want to change your code to send a request only after the previous request finishes, so that part of the code for handling the response from the server will be to queue up the next request. That will be a lot better than queuing up a bunch of requests without checking if they're coming back. Also, use an onload handler to make sure the code starts only after the page finishes loading. If you're clobbering the server with requests every second while you're trying to download the rest of the page components it probably won't even finish downloading the entire page.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...