Record, spare
- <?php
- $host = ' www.google.com '; To ping the address, can also be IP
- $port = ' 80 '; The port to Ping
- $num = 3;
- function Microtime_float ()
- {
- List ($usec, $sec) = Explode ("", Microtime ());
- Return ((float) $usec + (float) $sec);
- }
- function ping ($host, $port)
- {
- $time _start = Microtime_float ();
- $ip = gethostbyname ($host);
- $fp = @fsockopen ($host, $port,& $errno,& $errstr, 1);
- if (! $fp) return to ' Replay time out! ';
- $get = "Get/http/1.1\r\nhost:" $host. " \r\nconnection:close\r\n\r\n ";
- @fputs ($fp, $get);
- @fclose ($FP);
- $time _end = Microtime_float ();
- $time = $time _end-$time _start;
- $time = Ceil ($time * 1000);
- Return ' Reply from ' $ip. ': Time= '. $time. ' Ms<br/> ';
- }
- Echo ' Pinging '. $host. ' ['. gethostbyname ($host). '] With Port: '. $port. ' Data:<br/><br/> '. \ r \ n ";
- for ($i = 0; $i < $num; $i + +)
- {
- Ping ($host, $port);
- Sleep (1);
- Ob_flush ();
- Flush ();
- }
- ?>
This digest is from http://www.cnblogs.com/luoine/archive/2010/12/01/1893156.html