tags:

views:

44

answers:

2

Hi, In my webpage, I need to display the some information which will be updating frequently. For that I am using ajax calls, and showing it in the page using innerHTML. Im making the ajax request on each 3 seconds.. And in the php page (ajax request handler), Im opening the mysql connection using mysql_connect and at the end of the script Im closing the connection using mysql_close. But the server is getting slow because of the repeated calls. Is there any alternate solution ? Or how can I improve the performance of this ?

+1  A: 

You should consider Micro Optimization

Also you may want to keep your connection persistent using mysql_pconnect
No hard and fast need to close your connection each time; it is closed upon end of script.

Your server is mainly getting slow because of calls after every 3 seconds. Try to find an alternative to that if you can.

Sarfraz
In addition to this answer, try retrieve your data from ajax as JSON, in case the ammount of html is too big, dealing with the output on the client side.
yoda
Is it good to give mysql_pconnect if there are more number of users ? Also whether the amount of data it returns makes the server slow ?
binoy
A: 
  • Make the query every 6 seconds?
  • Make sure you're only returning -changed- data, and apply a diff instead of returning the whole set
  • Cache as best as you can, rather than hitting the DB every time, if possible. For instance, if the data updates frequently, but is the same for everyone, you could have it only query every 5 seconds, and have the update read the cached values (write data to disk, or whatever works in your setup)
James
Ya, I have thought about the caching.. But the code is like a tracking code, all the records are changing frequently. Any other way ?
binoy