How to check my server's upload and download speed?

29,758

Solution 1

Try:

<?php

$link = 'http://speed.bezeqint.net/big.zip';
$start = time();
$size = filesize($link);
$file = file_get_contents($link);
$end = time();

$time = $end - $start;

$size = $size / 1048576;

$speed = $size / $time;

echo "Server's speed is: $speed MB/s";


?>

Solution 2

If you have the remote desktop, then install a web browser and go to speedtest.net and test a speed.

If not, here's how you can test your server's download speed:

  • log in as root
  • type wget http://cachefly.cachefly.net/100mb.test
  • you'll see something like 100%[======================================>] 104,857,600 10.7M/s - 10.7M/s is a download speed.

If you have more than 1 server, you can test upload speed by transfering files between 2 servers.

Solution 3

Have it connect to a server you know runs fast (such as Google). Then, measure how long it takes from sending the first packet to receiving the first packet - that's your upload time. The time from receiving the first to last packets is the download time. Then divide by the amount of data transferred and there's your result.

Example:

$times = Array(microtime(true));
$f = fsockopen("google.com",80);
$times[] = microtime(true);
$data = "POST / HTTP/1.0\r\n"
       ."Host: google.com\r\n"
       ."\r\n"
       .str_repeat("a",1000000); // send one megabyte of data
$sent = strlen($data);
fputs($f,$data);
$firstpacket = true;
$return = 0;
while(!feof($f)) {
    $return += strlen(fgets($f));
    if( $firstpacket) {
        $firstpacket = false;
        $times[] = microtime(true);
    }
}
$times[] = microtime(true);
fclose($f);
echo "RESULTS:\n"
    ."Connection: ".(($times[1]-$times[0])*1000)."ms\n"
    ."Upload: ".number_format($sent)." bytes in ".(($times[2]-$times[1]))."s (".($sent/($times[2]-$times[1])/1024)."kb/s)\n"
    ."Download: ".number_format($return)." bytes in ".(($times[3]-$times[2]))."s (".($return/($times[3]-$times[2])/1024)."kb/s)\n";

(You will get an error message from Google's servers, on account of the Content-Length header missing)

Run it a few times, get an average, but don't run it too much because I don't think Google would like it too much.

Share:
29,758
HTMHell
Author by

HTMHell

Updated on July 09, 2022

Comments

  • HTMHell
    HTMHell almost 2 years

    I bought a server and I need to check it's internet connection (speed).

    Is there an easy way to do that?

    I googled but I couldn't find anything...

    I did this:

    <?php
    
    $link = 'http://speed.bezeqint.net/big.zip';
    $start = time();
    $size = filesize($link);
    $file = file_get_contents($link);
    $end = time();
    
    $time = $end - $start;
    
    $speed = $size / $time;
    
    echo "Server's speed is: $speed MB/s";
    
    
    ?>
    

    Is it correct?