Record it, and use it later? Php $ host = 'www .google.com '; // The IP address to be pinged, or IP $ port = '80'; // port $ num = 3 to be pinged; functionmicrotime_float () {list ($ usec, $ sec) = explode (, microti
Record it and use it later
-
- $ 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 \ r \ nHost:". $ host. "\ r \ nConnection: Close \ 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 ';
- }
- Echo 'pinging'. $ host. '['. gethostbyname ($ host). '] with Port:'. $ port. 'of data: '. "\ R \ n ";
- 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