I used this script once.. and today I found it and I thought I'll make ta tutorial about it.. It's very very simple so you will learn it quickly
First.. we have to create a new function.
PHP Code:
<?php
function track($host, $port, $timeout) {
It will create a new function "track" that requires host, port and timeout parameters..
PHP Code:
$firstTime = microtime(true);
$firstTime = microtime(true); - It will get a first time in microseconds
Now let's connect to this site
PHP Code:
$sock = fSockOpen($host, $port, $errno, $errstr, $timeout);
$sock = fSockOpen($host, $port, $errno, $errstr, $timeout); - This function/variable connects to the site
If that $sock variable don't get a response then let's display the error
PHP Code:
if (!$sock) {
echo "<b>Offline</b>";
}
Now let's get the another time
PHP Code:
$secondTime = microtime(true);
And now let's get the response time, let's show it and close our function
PHP Code:
$ping = round((($secondTime - $firstTime) * 1000), 0);
echo $ping." ms";
}
$ping = round((($secondTime - $firstTime) * 1000), 0); - Calculates the ping
echo $ping." ms"; - Shows the ping
} - Ends our function
Now let's get CodeCall.Net's ping
PHP Code:
track("www.codecall.net", 80, 10);
?>
I told you it is simple

Here's the full script:
PHP Code:
<?php
function track($host, $port, $timeout) {
$firstTime = microtime(true);
$sock = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$sock) {
echo "<b>Offline</b>";
}
$secondTime = microtime(true);
$ping = round((($secondTime - $firstTime) * 1000), 0);
echo $ping." ms";
}
track("www.codecall.net", 80, 10);
?>