Get your network speed in PHP

Description

The following code shows how to get your network speed.

Example


<?php//from   w  w w .  ja  va2s. c  om

    // Retrieve the data to send to the user
    $data = file_get_contents("a.php");

    // Determine the data's total size, in Kilobytes
    $fsize = filesize("a.php") / 1024;

    // Define the start time
    $start = time();

    // Send the data to the user
    echo "<!-- $data -->";

    // Define the stop time
    $stop = time();

    // Calculate the time taken to send the data
    $duration = $stop - $start;

    // Divide the file size by the number of seconds taken to transmit it
    $speed = round($fsize / $duration,2);

    // Display the calculated speed in Kilobytes per second
    echo "Your network speed: $speed KB/sec.";

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions