{"id":2863,"date":"2022-08-14T10:44:23","date_gmt":"2022-08-14T05:44:23","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2863"},"modified":"2022-08-14T10:53:34","modified_gmt":"2022-08-14T05:53:34","slug":"php-script-to-test-detect-internet-speed","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/","title":{"rendered":"PHP Script to Test\/Detect Internet Speed"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to test\/detect your internet connection speed using the latest PHP version.<\/p>\n\n\n\n<p>First of all, create a new PHP file <code>index.php<\/code> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">index.php<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n$kb = 1024;\necho &quot;Streaming $kb Kb...&lt;!-&quot;;\nflush();\n$time = explode(&quot; &quot;,microtime());\n$start = $time[0] + $time[1];\n\nfor($x = 0; $x &lt; $kb; $x++)\n{\n    echo str_pad('', 1024, '.');\n    flush();\n}\n\n$time = explode(&quot; &quot;,microtime());\n$finish = $time[0] + $time[1];\n$deltat = $finish - $start;\necho &quot;-&gt;&lt;br \/&gt;Test finished in $deltat seconds&lt;br \/&gt;&quot;;\necho &quot;Your internet speed is &quot;. round($kb \/ $deltat, 3).&quot;Kb\/s&quot;;\n?&gt;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code Explanation<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a new integer variable <code>$kb<\/code> and set its value to <code>1024<\/code>. Basically, we will use this variable in a <code>for<\/code> loop to specify the number of iterations.<\/li><li>We then use the <code>microtime()<\/code> function at the start and end of the <code>for<\/code> loop to track the start\/end time of the loop.<\/li><li>After that, we created a new variable <code>$deltat<\/code> that will hold the value of &#8220;loop finish time&#8221; minus &#8220;loop start time&#8221;. It means that this variable will tell us how much time was taken by the <code>for<\/code> loop to finish.<\/li><li>Finally, we will figure out the internet connection speed by dividing the <code>$kb<\/code> variable with <code>$deltat<\/code> and rounding the value to 3 decimal places using the <code>round()<\/code> function.<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; <a title=\"PHP Script to Test\/Detect Internet Speed\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/\" aria-label=\"Read more about PHP Script to Test\/Detect Internet Speed\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2868,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Script to Test\/Detect Internet Speed<\/title>\n<meta name=\"description\" content=\"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\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Script to Test\/Detect Internet Speed\" \/>\n<meta property=\"og:description\" content=\"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\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-14T05:44:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-14T05:53:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"880\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Script to Test\/Detect Internet Speed","description":"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","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/","og_locale":"en_US","og_type":"article","og_title":"PHP Script to Test\/Detect Internet Speed","og_description":"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","og_url":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-08-14T05:44:23+00:00","article_modified_time":"2022-08-14T05:53:34+00:00","og_image":[{"width":880,"height":495,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"PHP Script to Test\/Detect Internet Speed","datePublished":"2022-08-14T05:44:23+00:00","dateModified":"2022-08-14T05:53:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/"},"wordCount":186,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/","url":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/","name":"PHP Script to Test\/Detect Internet Speed","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg","datePublished":"2022-08-14T05:44:23+00:00","dateModified":"2022-08-14T05:53:34+00:00","description":"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","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/internet_speed_test_php.jpg","width":880,"height":495,"caption":"php internet speed test script"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/php-script-to-test-detect-internet-speed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP Script to Test\/Detect Internet Speed"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"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.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2863"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2863\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/2868"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}