php模拟ping
100人浏览 2024-11-14 10:04:39
效果图:

代码:
<?php $host = 'item.taobao.com'; //ping的地址,也可以是IP $port = '80'; //ping的端口 $num = 3; echo 'Pinging ' . $host . ' [' . gethostbyname($host) . '] with Port:' . $port . ' of data:<br /><br />' . "\r\n"; for ($i = 0; $i < $num; $i++) { // list($usec, $sec) = explode(" ", microtime()); $time_start = microtime(1); // ((float) $usec + (float) $sec); $ip = gethostbyname($host); // $fp = @fsockopen($host, $port); $fp = @fsockopen($host, $port, $errno, $errstr, 1); if (!$fp) { echo 'replay time out!<br />'; continue; } $get = "GET / HTTP/1.1\r\nHost:" . $host . "\r\nConnection: Close\r\n\r\n"; @fputs($fp, $get); @fclose($fp); // list($usec, $sec) = explode(" ", microtime()); $time_end = microtime(1); //((float) $usec + (float) $sec); $time = $time_end - $time_start; $time = ceil($time * 1000); echo 'Reply from ' . $ip . ': time=' . $time . 'ms<br />'; sleep(1); ob_flush(); flush(); }
相关推荐
-
第18问:MySQL CPU 高了,怎么办?2025-02-24 10:27:18
-
mysql索引类型 normal, unique, full text
mysql索引类型 normal, unique, full text2025-02-24 10:05:05 -
uwsgi+django+nginx 搭建部分总结2025-02-24 10:03:33
-
使用Docker配置Nginx环境部署Nextcloud2025-02-24 10:02:03
-
Nginx安装和怎么使用2025-02-24 10:00:45