XHanch Studio Log in | Register | Cart

Forum

[Function] Display ...
 
Notifications
Clear all

[Function] Display your Linux average server loads with PHP

1 Posts
1 Users
0 Likes
850 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

Here is the PHP function to show/display your Linux average server load with PHP.
With this method, you won't need to access your server via WHM, SSH, or any other server tools/panels if you just want to see your average server loads.

<?php
    function get_avg_svr_lod($win = 0) {
        $opr_sys = strtolower(PHP_OS);
        $lod = '';
        if(strpos($opr_sys, "win") === false) {
            if(file_exists("/proc/loadavg")) {
                $lod = file_get_contents("/proc/loadavg");
                $lod = explode(' ', $lod);
            }elseif(function_exists("shell_exec"))
                $lod = explode(' ', 'uptime');           
        }
        return $lod;
    }

    $res = get_avg_svr_lod();
?>

Example of usage:

<font style="font-family:'courier new';font-size:12px">
Past 1 Minute &nbsp;&nbsp;: <?php echo $res[0]; ?><br/>
Past 5 Minutes &nbsp;: <?php echo $res[1]; ?><br/>
Past 15 Minutes : <?php echo $res[2]; ?>
</font>
 
Posted : 10/02/2012 7:41 am
Share:

× Close Menu