扫码关注官方订阅号
这是接口:http://api.k780.com:88/?app=w...
现在问题就是无论我怎么用curl或者是file_get_contents()来请求接口都很慢,自己也查了下,说是将域名换成ip就好了,但ip有时候会跟换,而且这网站配置了虚拟域名,用ip访问不了
想问下有没有方法能缩短时间?
闭关修行中......
简单用curl测了下,三次分别耗时0.229s, 0.127s和0.117s,挺快的呀。从浏览器访问也是这个速度。 LZ还是应该检查代码,是不是在其他地方有高耗时的操作 -- 代码看不出来的话就打点看看时间呗。
0.229s
0.127s
0.117s
➜ ~ psysh Psy Shell v0.6.1 (PHP 5.5.35 — cli) by Justin Hileman >>> >>> >>> >>> $x = curl_init('http://api.k780.com:88/?app=weather.today&weaid=%E9%9D%92%E6%B5%A6&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json') => curl resource #291 >>> $s = microtime(true); curl_exec($x); $e = microtime(true); {"success":"1","result":{"weaid":"41","days":"2016-08-09","week":"星期二","cityno":"qingpu","citynm":"青浦","cityid":"101020800","temperature":"33℃/27℃","temperature_curr":"29℃","humidity":"79%","weather":"阵雨","weather_curr":"阵雨","weather_icon":"http://api.k780.com:88/upload/weather/d/3.gif","weather_icon1":"","wind":"东风","winp":"2级","temp_high":"33","temp_low":"27","temp_curr":"29","humi_high":"0","humi_low":"0","weatid":"4","weatid1":"","windid":"10","winpid":"203"}}⏎ => 1470706896.6087 >>> $e - $s => 0.22865319252014 >>> $s = microtime(true); curl_exec($x); $e = microtime(true); {"success":"1","result":{"weaid":"41","days":"2016-08-09","week":"星期二","cityno":"qingpu","citynm":"青浦","cityid":"101020800","temperature":"33℃/27℃","temperature_curr":"29℃","humidity":"79%","weather":"阵雨","weather_curr":"阵雨","weather_icon":"http://api.k780.com:88/upload/weather/d/3.gif","weather_icon1":"","wind":"东风","winp":"2级","temp_high":"33","temp_low":"27","temp_curr":"29","humi_high":"0","humi_low":"0","weatid":"4","weatid1":"","windid":"10","winpid":"203"}}⏎ => 1470706909.3393 >>> $e - $s => 0.12704491615295 >>> $s = microtime(true); curl_exec($x); $e = microtime(true); {"success":"1","result":{"weaid":"41","days":"2016-08-09","week":"星期二","cityno":"qingpu","citynm":"青浦","cityid":"101020800","temperature":"33℃/27℃","temperature_curr":"29℃","humidity":"79%","weather":"阵雨","weather_curr":"阵雨","weather_icon":"http://api.k780.com:88/upload/weather/d/3.gif","weather_icon1":"","wind":"东风","winp":"2级","temp_high":"33","temp_low":"27","temp_curr":"29","humi_high":"0","humi_low":"0","weatid":"4","weatid1":"","windid":"10","winpid":"203"}}⏎ => 1470706919.4255 >>> $e - $s => 0.11749792098999
你确定是php在这一步慢?最好将整个PHP执行顺序依次输出时间戳看一下到底哪一步慢。
不慢吖,试了请求返回0.2s
使用xdebug或者xhprof进行性能分析。
遇到了一样的问题,你这个url直接访问只有0.12s,但通过php访问5.3s
是不是楼主自己的dns服务器比较卡
服务器到接口之间速度慢
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
简单用curl测了下,三次分别耗时
0.229s,0.127s和0.117s,挺快的呀。从浏览器访问也是这个速度。 LZ还是应该检查代码,是不是在其他地方有高耗时的操作 -- 代码看不出来的话就打点看看时间呗。你确定是php在这一步慢?最好将整个PHP执行顺序依次输出时间戳看一下到底哪一步慢。
不慢吖,试了请求返回0.2s
使用xdebug或者xhprof进行性能分析。
遇到了一样的问题,你这个url直接访问只有0.12s,但通过php访问5.3s
是不是楼主自己的dns服务器比较卡
服务器到接口之间速度慢