Record it and use it later
- <? Php
- $ Host = www.google.com; // the IP address to be pinged. It can also be an IP address.
- $ Port = 80; // port to be pinged
- $ 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 replay time out !;
- $ Get = "GET/HTTP/1.1 Host:". $ host. "Connection: Close ";
- @ 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. of data: <br/> ."";
- For ($ I = 0; $ I <$ num; $ I ++)
- {
- Ping ($ host, $ port );
- Sleep (1 );
- Ob_flush ();
- Flush ();
- }
- ?>
This article from http://www.cnblogs.com/luoine/archive/2010/12/01/1893156.html