Results 1 to 10 of 10
  1. #1

    how to check load server with php?

    i see a few month ago a simply script to check load on a server, only with one line, anyone remember or know how to do it?

    i don't want a complete system for server loads, uptimes, etc, for that i have nagios, what i'm looking for it's to make a simple website to check all the servers loads and refresh it every 5 minutes for example, any idea?

    something like :

    check server1 and show load
    check server2 and show load
    check server3 and show load
    check server4 and show load


    thanks.
    honesting.es honest european provider

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    94
    I don't think that you can check the server load remotly with PHP without having a file on the server.

  3. #3
    yes, it's possible, i did it in the past ... uf
    honesting.es honest european provider

  4. #4
    Join Date
    Oct 2004
    Location
    UK
    Posts
    487
    This is the only way I know of and the way I have always used:

    PHP Code:
    <?php

    function server_load()
    {

    $load_file "/proc/loadavg";

    $handle fopen($load_file"r");
    $contents fread($handle1024);
    fclose($handle);

    $loads explode(" "$contents);

    return 
    $loads[0];

    }

    ?>

  5. #5
    @Xenatino: You can do the same using shorter code:
    PHP Code:
    <?php

    function server_load() {
    return 
    array_shiftexplode' 'file_get_contents'proc/loadavg' ) ) );
    }

    ?>
    (anyway, it can be done more efficient using just strings, arrays don't need to be involved)

    @pueblosnet:

    The simplest way to display server load is:
    PHP Code:
    <?php echo `cat /proc/loadavg | cut -d" " -f1`; ?>
    (you need to be allowed to execute shell commands)

    And of course RangerOfFire is right - you need to execude code on destination machine. There is no way to check server's load if this server doesn't provide such service (which can be very simple web-service provided with this one line of PHP code above.

  6. #6
    I remeber that the code i'm looking for could check the load of a external server, i'm going to look for that hard and if found i tell you, thanks.
    honesting.es honest european provider

  7. #7
    This remote server would need to provide a service reporting its load (or just run one line of your PHP script which would act as such service) - then your code can chceck and report this remote server load.

  8. #8
    Join Date
    Jun 2004
    Location
    Bay Area -USA
    Posts
    1,738
    Originally posted by tygryz79

    PHP Code:
    <?php

    function server_load() {
    return 
    array_shiftexplode' 'file_get_contents'proc/loadavg' ) ) );
    }

    ?>
    Ohh... I love efficient coding :-D
    <<< Please see Forum Guidelines for signature setup. >>>

  9. #9
    That wasn't efficient. :)
    It was just shorter, one-line implementation of Xenatino's algorithm.

  10. #10
    Join Date
    Oct 2004
    Location
    UK
    Posts
    487
    Thanks tygryz79, I've editing my function script to include that new, shorter code now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •