Tutorials

PHP Script to Test/Detect Internet Speed

In this tutorial, you will learn how to test/detect your internet connection speed using the latest PHP version.

First of all, create a new PHP file index.php and add the following code to it. After that open this file using a server like Apache, Nginx, etc. As you probably want to test this script in a development environment so I would recommend you to use XAMPP.

index.php

<?php
$kb = 1024;
echo "Streaming $kb Kb...<!-";
flush();
$time = explode(" ",microtime());
$start = $time[0] + $time[1];

for($x = 0; $x < $kb; $x++)
{
    echo str_pad('', 1024, '.');
    flush();
}

$time = explode(" ",microtime());
$finish = $time[0] + $time[1];
$deltat = $finish - $start;
echo "-><br />Test finished in $deltat seconds<br />";
echo "Your internet speed is ". round($kb / $deltat, 3)."Kb/s";
?>

Code Explanation

  1. Create a new integer variable $kb and set its value to 1024. Basically, we will use this variable in a for loop to specify the number of iterations.
  2. We then use the microtime() function at the start and end of the for loop to track the start/end time of the loop.
  3. After that, we created a new variable $deltat that will hold the value of “loop finish time” minus “loop start time”. It means that this variable will tell us how much time was taken by the for loop to finish.
  4. Finally, we will figure out the internet connection speed by dividing the $kb variable with $deltat and rounding the value to 3 decimal places using the round() function.
Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

Obsidian vs Notion (2026): I tested both for 6 months

If you have been searching for the right note-taking or knowledge management app, you have…

May 31, 2026

AnyType Alternatives: 10 Best Tools for Knowledge Management in 2026

Looking for AnyType alternatives? You're not alone. AnyType has gained popularity as a privacy-focused, local-first…

May 31, 2026

Notion Alternatives – Best Note-taking & Wiki Tools

Notion is a popular all-in-one workspace, but many users seek alternatives for different needs (free…

May 31, 2026

Best Logseq Alternatives in 2026: Find Your Perfect Knowledge Management Tool

Logseq is a beloved tool in the personal knowledge management (PKM) community. It's free, open-source,…

May 30, 2026

Webshare Alternatives: 8 Best Proxy Providers to Use in 2026

Looking for a Webshare alternative? You're not alone. Webshare is a popular proxy service with…

May 30, 2026

Docker Alternatives in 2026: The Complete Guide to Container Tools

Docker changed software development forever. It made containers accessible, gave developers a simple workflow, and…

May 30, 2026