Check Server Load On Shared Host Using PHP





If you are using a shared hosting plan to host your website, chances are that you are sharing the same server with hundreds, and maybe even thousands, of other domains. Does this lead to performance issues? Quite possibly. But how do you check for that? Many hosting companies will post server status, but all that really gives you is whether the server is up or down. Server status does not tell you what’s the load on the server.

Why does this matter? This is important because slow servers invariably lead to slow page load time. In extreme cases, it may cause the website to fail to load. So, it is a good idea to find out what’s the server load on your shared host machine.

If you have Linux/Unix-based hosting, and you can access the machine directly via SSH, you can easily find the server load information. For pretty much all the shared hosting plans, though, the hosting company does not provide direct SSH access. For those cases, we’ll need to rely on another method. One way I have done this is to use a simple PHP script:

<?php
$uptime = shell_exec(“uptime”);
echo “$uptime”;
?>

Save the above 4 lines in a file called “load.php”. Upload the file into your server, and go to http://yoursite/load.php, you’ll get an output similar to the following:

00:55:53 up 338 days, 7:50, 0 users, load average: 5.89, 4.52, 3.84

The server load information comes after the phrase “load average”. The 3 numbers represent the average server load in the past 1 minute, the past 5 minutes, and the past 15 minutes, respectively. For a single-CPU hosting server, you want to see numbers below 1. If the number is between 1 and 2, that means there is some wait time in CPU processing, but things are not too bad yet. When you see numbers above 2, that means the server is quite overloaded and your website will likely be slow. A slow-loading website is not a good user experience and will lead to higher percentage of visitors leaving before the page is even loaded. In the sample output above, the webmaster should seriously start looking for a new web hosting company, as the server load average has been consistently above 3.8 during the past 15 minutes.

The guidelines above assume a single-CPU server. If your server is a 2-CPU (or single CPU but duo-core), you multiply the previous ratios by 2, meaning you’ll want to see server load numbers of 2 or less in this case.

Tags: Tags: , ,