Jump to content

refreshin and GET requests


bPHP

Recommended Posts

Hi! I have a code in ajax that is constantly calling a php function to check a database. Even though the php only sends information when it needs to (when the database was updated) if I see my page in firebug, I can see that it is constantly creating requests. How can I avoid this? Is there anyway to have it more clean?

 

Thanks!

Link to comment
Share on other sites

Do you have your ajax call in a setInterval? Or do you setTimeout after your function and call the same function?

 

I setTimeout. It is something like this:

 

mTimer = setTimeout('getChatText();',100); //Refresh chat text

 

getChatText looks like this:

 

function getChatText() {

if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {

receiveReq.open("GET", 'chat.php', true);

receiveReq.onreadystatechange = handleReceiveChat;

receiveReq.send(null);

}

}

 

Chat.php sends back a JSON string that my function handleReceiveChat processes appropriately.

Link to comment
Share on other sites

I know... I have it set to 100 because I want it to be faster than one second... In the tracking terminal one second still looks ridiculous.

 

Yes it should send requests, but I've seen other chats and my firebug does not show constant requests. I'm trying to improve my performance as much as possible, I'm constantly sending requests, and each request makes a SELECT from the db... It works fine right now but I'm afraid of what is going to happen if I have 200-300 users all chatting at the same time with this design.

Link to comment
Share on other sites

How many active users do you have chatting? Unless you have a writing icon or w/e to notify the other user that their partner is writing, you can probably just use 1 - 1.5 (1000 - 1500) intervals. 100 is a shit load

 

86,400 seconds a day.. * 10 per second...

 

864,000 * 2 = 1,728,000 requests to your server.. and that is if there is only one user chatting with one partner...

 

I can't imagine that is good for a server that is unprepared.

Link to comment
Share on other sites

I don't have any yet because my website is still in development. I've tried with 4 users and worked fine, but yes, it is a big load for the server. And yes, I have a notification that the other partner is writing. I just can't figure out how to do this in a neat way. Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.