Quick script to test page load times (speed test)

Use this script nicely and wisely, I'm not responsible for the abuse of this script. The script by default waits 2 seconds before querying the urls.

In order for this script to work, you must have curl installed on your system. This script is assuming you are in a UNIX environment. If you want to use this on a Windows machine, you are going to have to install curl and modify the script below. Also, wget will work, but you'll have to modify the script.

<?php
$url = 'http://www.example.com';
$number_of_requests = 10;
$sleep_time = 2;

function getmicrotime() {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
}

$a_speed = array();

$tmp_file = 'delete_me' . md5(rand(1,999) . date("Y-m-d H:i:s"));

for($i=0; $i<$number_of_requests; $i++){
        $page_load_start = getmicrotime();

        system("clear");
        echo("[{$i} of {$number_of_requests}]\n");
        exec("curl -sk {$url} > {$tmp_file}");

        $page_load_end = getmicrotime();

        $page_load = round($page_load_end - $page_load_start,5);

        $a_speed[] = $page_load;

        sleep($sleep_time);
}

$average_load_time = round(array_sum($a_speed) / $number_of_requests,2);
$total_load_time = array_sum($a_speed);

unlink($tmp_file);

print("Average load time: " . $average_load_time . "\n");
echo <<<eof
        Average load time: {$average_load_time}
        Total load time of {$number_of_requests} requests: {$total_load_time}\n
eof
;
?>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.