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(); }
相关推荐
-
MySQL 中的反斜杠 \\,真是太坑了2025-04-21 01:42:45
-
mysql修改主键为自增 ,如果自增达到最大值,新增加数据会怎样?
mysql修改主键为自增 ,如果自增达到最大值,新增加数据会怎样?2025-04-21 01:31:46 -
Nginx学习笔记 autoindex on2025-04-21 00:26:47
-
.MySQL中的BETWEEN(在某个范围)2025-04-21 00:04:20
-
nginx设置目录浏览并支持中文2025-04-21 00:00:35