Results 1 to 9 of 9
  1. #1
    Join Date
    May 2010
    Posts
    36

    PHP - how to get remote server load time?

    If I want to know my server's time load then I use this
    PHP Code:
    number_format(microtime(true) - $_SERVER['REQUEST_TIME'
    What if I want to display other sites load time on my site?

    i.e: google load time = 0.55ms
    yahoo load time = 0.1 ms


    Please help

  2. #2
    Hello,

    Place this php file on your remote server and use iFrame on your 2nd server.


    <?php

    $uptime = exec("uptime");

    $parts = split("load average:", $uptime);

    $load = split(", ", $parts[1]);

    echo "Current load: " . $load[0];

    ?>

    or


    <?php

    function server_load()
    {

    $load_file = "/proc/loadavg";

    $handle = fopen($load_file, "r");
    $contents = fread($handle, 1024);
    fclose($handle);

    $loads = explode(" ", $contents);

    return $loads[0];

    }

    ?>

    or

    <?php echo `cat /proc/loadavg | cut -d" " -f1`; ?>
    Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
    WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
    DemoTiger.com - Buy Demo Videos for your Hosting Company

  3. #3
    Sorry, I just found a good script for checking remote server load time.

    Don't forget to replace site name and maybe port(I think 80 is default and you don't need to change port)

    <?php
    // attempt to open a socket on port 80 (HTTP) to the site in question
    // 30 is a timeout value, in seconds
    // if the connection completely fails, fsockopen() will return 0 and put error
    // code and messages into $errno and $errstr, respectively
    $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
    if (!$fp) {
    // report the error if the connection failed.
    echo "$errstr ($errno)<br />\n";
    }
    else {
    // put whatever code for a good connection here
    }
    // close the socket
    fclose($fp);
    }
    ?>

    and I think script is using fopen so you need to enable fopen in your .php.ini.
    Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
    WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
    DemoTiger.com - Buy Demo Videos for your Hosting Company

  4. #4
    Join Date
    May 2010
    Posts
    36
    Quote Originally Posted by DewlanceHosting View Post
    Sorry, I just found a good script for checking remote server load time.

    Don't forget to replace site name and maybe port(I think 80 is default and you don't need to change port)




    and I think script is using fopen so you need to enable fopen in your .php.ini.
    OK, this test the connection if fail or not within 30 seconds.
    If the connection is good, how to know load time of www.example.com in ms?

  5. #5
    Quote Originally Posted by imanewbie View Post
    OK, this test the connection if fail or not within 30 seconds.
    If the connection is good, how to know load time of www.example.com in ms?
    Yes,
    <?php
    // attempt to open a socket on port 80 (HTTP) to the site in question
    // 30 is a timeout value, in seconds
    // if the connection completely fails, fsockopen() will return 0 and put error
    // code and messages into $errno and $errstr, respectively
    $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
    if (!$fp) {
    // report the error if the connection failed.
    echo "$errstr ($errno)<br />\n";
    }
    else {
    // put whatever code for a good connection here
    }
    // close the socket
    fclose($fp);
    }
    ?>
    Replace this line with your code(I post 2 - 3 code on my 1st reply and only you need to add any one code)
    Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
    WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
    DemoTiger.com - Buy Demo Videos for your Hosting Company

  6. #6
    Join Date
    May 2010
    Posts
    36
    Quote Originally Posted by DewlanceHosting View Post
    Yes,

    Replace this line with your code(I post 2 - 3 code on my 1st reply and only you need to add any one code)
    hmm, but the code you posted needed to put it on remote server?
    what If I want to check google.com load time.

    What i mean is same as http://www.iwebtool.com/speed_test?domain=google.com

  7. #7
    Quote Originally Posted by imanewbie View Post
    Its a site speed tester, you can find a lots of site speed tester script.


    You want to check site speed test or server load?


    hmm, but the code you posted needed to put it on remote server?
    what If I want to check google.com load time.
    No, you don't need to put this code on your remote server.
    Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
    WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
    DemoTiger.com - Buy Demo Videos for your Hosting Company

  8. #8
    Join Date
    May 2010
    Posts
    36
    Quote Originally Posted by DewlanceHosting View Post
    Its a site speed tester, you can find a lots of site speed tester script.


    You want to check site speed test or server load?



    No, you don't need to put this code on your remote server.
    I want to check site speed test but after I google I can find only the code for my own site, but I want the code to check others sites.

  9. #9
    Join Date
    Jun 2010
    Location
    Los Angeles
    Posts
    26
    from your linux console or through php's exec(), do:

    time wget -p http://www.google.com >/dev/null 2>&1

    it'll give you the results in milliseconds

Similar Threads

  1. Rsync High Load On Remote Server
    By prasant4u in forum Dedicated Server
    Replies: 3
    Last Post: 02-05-2011, 04:01 PM
  2. Replicating a (remote) MySQL database to improve PHP execution time
    By shought in forum Programming Discussion
    Replies: 15
    Last Post: 11-04-2010, 04:05 PM
  3. PHP Load time too big
    By Oakii in forum Web Design and Content
    Replies: 2
    Last Post: 04-18-2005, 03:41 AM
  4. remote server uptime and load average?
    By WFWH in forum Hosting Security and Technology
    Replies: 6
    Last Post: 10-28-2004, 05:16 PM

Posting Permissions

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