type
Post
status
Published
date
Mar 31, 2023
slug
3
summary
tags
category
技术分享
icon
password
pingAPI请求方式
Method: GET
请求地址
参数
url=要ping的域名
调用示例
源码
<?php $url = $_GET['url']; $port = '80'; $num = 1; //Ping次数 function mt_f (){ list($usec,$sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function ping_f($url,$port){ $time_s = mt_f(); $ip = gethostbyname($url); $fp = @fsockopen($url,$port); if(!$fp) return '回复超时!'; $get = "GET / HTTP/1.1||Host:".$url."||Connect:".$port."Close||"; fputs($fp,$get); fclose($fp); $time_e = mt_f(); $time = $time_e - $time_s; $time = ceil($time * 1000); return '时间 = '.$time.'ms'; } for($i = 0;$i < $num;$i++){ echo '正在PING: '.$url.' 来自 '.gethostbyname($url).' 的回复 '.ping_f($url,$port).'</br>'; sleep(0.1);//每次运行中间间隔0.1s ob_flush(); flush(); } ?>
- 作者:ingm23
- 链接:https://blog.to2.top/article/3
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。