Jump to content

Will an AJAX refresh overload the server?


Nathan Johnson

Recommended Posts

Hello,

 

I am using this code to refresh an element every 5000 milliseconds:

 

<script type="text/javascript">
   function changeTitle() {
   var title = $('.subjectContainer').html();
   document.title = title+' | WeeBuild Customer Support';
   }
$(document).ready(function() {
     $(".subjectContainer").load("subject.php?ticket=<?php echo $_GET[ticket]; ?>");
   var refreshId = setInterval(function() {
      $(".subjectContainer").load("subject.php?ticket=<?php echo $_GET[ticket]; ?>");
      changeTitle();
   }, 5000);
   $.ajaxSetup({ cache: false });
});
</script>

 

But, will this overload the server I'm on? I want to make sure before I use it. It doesn't seem like anything happens when I try it, but I just want to make sure. The file being loaded just contains a string of text that is retrieved from a database. The reason I am having it refresh is so it stays updated if it gets changed by a user. The server I am on is Stevie.

Link to comment
Share on other sites

Ajax is light weight. Also you are trying to retrieve data from db only , right? I think that won't make overload in server. I am not sure anyway.

 

Hi,

 

Yeah, the page just retrieves the subject of the ticket from the database and then the AJAX loads that page into the div. For example, here is the page that is being loaded into it:

 

http://weebuild.heliohost.org/employee/sub...?ticket=5156869

 

As you can see, it's just one line of text.

Link to comment
Share on other sites

All depends what the "subject.php" is doing, how many server resources it's using and how often will be called.

 

With just one visitor on your website reloading a "page" every 5 seconds I'm sure it will be fine.

With thousands visitors browsing website at the same time and every one of them reloading the "page" every 5 seconds it may be very significant amount of traffic even if "subject.php" is lightweight.

You know what kind of traffic your website will have and the common sense should help you decide.

 

Link to comment
Share on other sites

I'm not really sure what you're trying to do, since there isn't a test page. Where is the user going to change the title from, another page? It doesn't seem like it would cause much load, you don't have to worry about getting suspended or anything, but keep in mind that as visitors increase, you will start getting 500 Internal Server errors if you have too many page loads. Another solution would be to use the apc_* functions to cache whether the id has been updated or not so you don't have to go to the database every time.

Link to comment
Share on other sites

All depends what the "subject.php" is doing, how many server resources it's using and how often will be called.

 

With just one visitor on your website reloading a "page" every 5 seconds I'm sure it will be fine.

With thousands visitors browsing website at the same time and every one of them reloading the "page" every 5 seconds it may be very significant amount of traffic even if "subject.php" is lightweight.

You know what kind of traffic your website will have and the common sense should help you decide.

 

Subject.php gets the subject from the database and that's it. The code of subject.php is:

 

<?php
$ticket = $_GET['ticket'];
require_once('connection.php');
mysql_select_db("my_database") or die(mysql_error());
$result = mysql_query("SELECT * FROM tickets WHERE ticket='$ticket'");
$info = mysql_fetch_array($result);
$subject = $info['subject'];

if($subject != '' && $subject != null) {
echo $subject;
}
else {
echo "Ticket ID Invalid";
}
mysql_close($con);
?>

 

Also, I just changed it to every 5 minutes now, so it wont be a lot of requests and so there wont be any 500 internal server errors. (I don't think)

 

Thanks everyone for helping with this!

Link to comment
Share on other sites

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.   Paste as plain text instead

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