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 21:00] admin |
projects:speedtest [2022/08/16 21:30] (current) admin |
||
---|---|---|---|
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> |