This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:speedtest [2022/08/02 20:59] admin |
projects:speedtest [2022/08/16 21:30] (current) admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Projects: Speedtest ====== | ====== Projects: Speedtest ====== | ||
- | I'm testing out some new 5G antennas and after experimenting with a number of different ways to measure their performance I decided the most reliable and simplest way was just write a script that repeats a download and then plot the results in a graph. That allows me to average out any atmospheric interference (and more importantly average out all the other activity on my busy network). | + | I'm testing out some new 5G antennas and after experimenting with a number of different ways to measure their performance I decided the most reliable and simplest way was just write a script that repeats a download every minute and then plot the results in a graph. That allows me to average out any atmospheric interference (and more importantly average out all the other activity on my busy network). |
===== Download Speeds ===== | ===== Download Speeds ===== | ||
Line 16: | Line 16: | ||
while(true) { | while(true) { | ||
$time_start = microtime(true); | $time_start = microtime(true); | ||
- | $url = "https://putitonyourowndomain.com/testfile10"; | + | $url = "https://putitonyourowndomain.com/10mb-test-file"; |
$data = file_get_contents($url); | $data = file_get_contents($url); | ||
$time_end = microtime(true); | $time_end = microtime(true); | ||
Line 64: | Line 64: | ||
<?php | <?php | ||
$target_url = "https://www.yourdomain.co.uk/acceptupload.php"; | $target_url = "https://www.yourdomain.co.uk/acceptupload.php"; | ||
- | $file_name_with_full_path = "/home/seven/projects/speedtest/4mb-test-file"; | + | $file_name_with_full_path = "/tmp/4mb-test-file"; |
while(true) { | while(true) { | ||
$time_start = microtime(true); | $time_start = microtime(true); | ||
Line 91: | Line 91: | ||
</code> | </code> | ||
- | That will return in a format similar to the download test: | + | That will return in a format similar to the download test (datetime, seconds to download, average mb/s): |
<code> | <code> | ||
2022-08-02 20:49:44 4.6254539489746 0.86477998573237 | 2022-08-02 20:49:44 4.6254539489746 0.86477998573237 | ||
Line 99: | Line 99: | ||
===== Upload and Download ===== | ===== Upload and Download ===== | ||
This final version tries to download a 10Mb from my server, then tries to upload a 4Mb file to the ''acceptfile.php'' file (written above) hosted on my web server. Then it waits a minute and tries it again in a loop. | This final version tries to download a 10Mb from my server, then tries to upload a 4Mb file to the ''acceptfile.php'' file (written above) hosted on my web server. Then it waits a minute and tries it again in a loop. | ||
- | <code speedtest.php> | + | <code php speedtest.php> |
+ | <?php | ||
+ | $download_url = "https://www.yourdomain.co.uk/10mb-test-file"; | ||
+ | $download_size_mb = 10; | ||
+ | $upload_url = "https://www.yourdomain.co.uk/acceptupload.php"; | ||
+ | $upload_size_mb = 4; | ||
+ | $file_to_upload = "/tmp/4mb-test-file"; | ||
+ | |||
+ | while(true) { | ||
+ | $time_start = microtime(true); | ||
+ | $data = file_get_contents($download_url); | ||
+ | $time_end = microtime(true); | ||
+ | $download_time = $time_end - $time_start; | ||
+ | echo date("Y-m-d H:i:s")."\t"; | ||
+ | echo "DOWN\t$download_size_mb\t"; | ||
+ | echo $download_time."\t"; | ||
+ | echo ($download_size_mb/$download_time)."\n"; | ||
+ | |||
+ | $time_start = microtime(true); | ||
+ | $cFile = curl_file_create($file_to_upload); | ||
+ | $post = array('upload_file'=>$cFile); | ||
+ | $ch = curl_init(); | ||
+ | curl_setopt($ch, CURLOPT_URL,$upload_url); | ||
+ | curl_setopt($ch, CURLOPT_POST,1); | ||
+ | curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | ||
+ | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
+ | $result=curl_exec ($ch); | ||
+ | curl_close ($ch); | ||
+ | |||
+ | echo date("Y-m-d H:i:s")."\t"; | ||
+ | echo "UP\t$upload_size_mb\t"; | ||
+ | if($result == "OK") { | ||
+ | $time_end = microtime(true); | ||
+ | $upload_time = $time_end - $time_start; | ||
+ | echo $upload_time."\t"; | ||
+ | echo (4/$upload_time)."\n"; | ||
+ | } else { | ||
+ | echo "Error downloading ($result)\n"; | ||
+ | } | ||
+ | sleep(60); | ||
+ | } | ||
+ | |||
+ | ?> | ||
</code> | </code> |