大佬教程收集整理的这篇文章主要介绍了PHP Curl API响应时间与不同的服务器不同,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
{ "code": 200,"response_time": { "time": 0.43,"measure": "seconds" } }
服务器B通过使用微秒来标记请求块的开始和结束来计算每个任务的完成时间.但是当我在服务器A上使用curl来调用服务器B时,我在执行时间方面得到了非常奇怪的结果:
$url = "https://example.com/api"; /*server B address. I've tried IP address as well without any change in results. This must go over a SSL connection. */ $start_time = microtime(true); $curl2 = curl_init(); curl_setopt($curl2,CURLOPT_URL,$url); curl_setopt($curl2,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl2,CURLOPT_SSL_VERIFYPEER,falSE); curl_setopt($curl2,CURLOPT_USERAGENT,"Server A User Agent"); $result = curl_exec($curl2); $httpCode = curl_geTinfo($curl2,CURLINFO_http_CODE); $@R_323_10586@l_time = curl_geTinfo($curl2,CURLINFO_@R_323_10586@L_TIME); $connect_time = curl_geTinfo($curl2,CURLINFO_CONNECT_TIME); $namelookup_time = curl_geTinfo($curl2,CURLINFO_NAMELOOKUP_TIME); $end_time = microtime(true); $timeDiff = round(((float)$end_time - (float)$start_timE),3);
每次时间检查都会得到以下信息:
$timeDiff = 18.7381 (Using Microseconds) $@R_323_10586@l_time = 18.7381 (Transfer TimE) $connect_time = 0.020679 $namelookup_time = 0.004144
所以我不确定为什么会这样.有没有更好的方法从网络中另一台拥有API的服务器获取数据?如果Twitter的Site从另一台不是API服务器的服务器上消耗他们的API就好了.我认为,卷曲到API的时间与API报告的时间非常相似.我知道API没有考虑网络流量和打开连接的速度 – 但是对于我而言,18秒对0.43似乎很奇怪.
这里有什么想法?
1)使用ping命令检查响应时间.
From Server-A: ping Server-B-IP From Server-B: ping Server-A-IP
2)同样,您可以使用traceroute(用于Windows tracert)命令来检查响应时间.你应该立即得到答复.
From Server-A: traceroute Server-B-IP From Server-B: traceroute Server-A-IP
3)使用wget或curl命令行下载一个大文件(比方说100 MB)从一台服务器到另一台服务器,然后检查它们需要多长时间.例如使用wget:
From Server-B: wget http://server-A-IP/test/test-file.flv From Server-A: wget http://server-B-IP/test/test-file.flv
4)除了这些基本的例行检查外,您还可以使用一些高级工具对此网络问题进行排序.例如,来自以下两个链接的命令/示例:
Test network connection performance between two Linux servers
Command line tool to test bandwidth between 2 servers
以上是大佬教程为你收集整理的PHP Curl API响应时间与不同的服务器不同全部内容,希望文章能够帮你解决PHP Curl API响应时间与不同的服务器不同所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。