Nathan Johnson Posted September 4, 2011 Posted September 4, 2011 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.
PenTester Posted September 4, 2011 Posted September 4, 2011 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.
Nathan Johnson Posted September 4, 2011 Author Posted September 4, 2011 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.
Piotr GRD Posted September 4, 2011 Posted September 4, 2011 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.
Guest xaav Posted September 4, 2011 Posted September 4, 2011 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.
Nathan Johnson Posted September 5, 2011 Author Posted September 5, 2011 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now