Thread: Get site's ping
View Single Post
  #1 (permalink)  
Old 04-29-2008, 07:23 AM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 935
Last Blog:
AdStar Ad Control Pa...
Rep Power: 17
Jaan is just really niceJaan is just really niceJaan is just really niceJaan is just really nice
Send a message via MSN to Jaan
Default Get site's ping

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"8010);
?> 
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"8010);
?>
__________________


Cheap & Professional Web Design | Need help? Send a PM

Last edited by Jaan; 05-22-2008 at 07:14 AM.
Reply With Quote

Sponsored Links