How to measure web response time (http port 80) by Mikrotik

Dear expert
We are going to measure web server response time and develop PHP program using Mikrotik functions.
The code is shown in below. the output is response time in ms(millisecond).
Please advise;


<?php // check responsetime for a webbserver function pingDomain($domain){ $starttime = microtime(true); // supress error messages with @ $file = @fsockopen($domain, 80, $errno, $errstr, 10); $stoptime = microtime(true); $status = 0; if (!$file){ $status = -1; // Site is down } else{ fclose($file); $status = ($stoptime - $starttime) * 1000; $status = floor($status); } return $status; } echo pingDomain('[www.sanook.com](http://www.sanook.com)') ,ms, "
"; ?>

The fsockopen() requires you also specify the protocol (TCP or UDP).

Note also that with fsockopen(), you’re only measuring the connection time, not the time the web page will be retrieved in, thus skewing the results into a more positive light than they probably are.

(there’s also an undefined constant notice, but that’s not a big issue…)

With that in mind, all you really need to change is to replace the line

echo pingDomain('www.sanook.com') ,ms, "<br>"; 

with

echo pingDomain('tcp://www.sanook.com') ,"ms<br>"; 

Or alternatively, make pingDomain() add it explicitly at

$file = @fsockopen('tcp://' . $domain, 80, $errno, $errstr, 10);