1、老的curl访问方式以及耗时统计
<?php
function
curl_fetch(
$url
,
$timeout
=3){
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_TIMEOUT,
$timeout
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
$data
= curl_exec(
$ch
);
$errno
= curl_errno(
$ch
);
if
(
$errno
>0) {
$data
= false;
}
curl_close(
$ch
);
return
$data
;
}
function
microtime_float()
{
list(
$usec
,
$sec
) =
explode
(
" "
, microtime());
return
((float)
$usec
+ (float)
$sec
);
}
$url_arr
=
array
(
"taobao"
=>
"http://www.taobao.com"
,
"sohu"
=>
"http://www.sohu.com"
,
"sina"
=>
"http://www.sina.com.cn"
,
);
$time_start
= microtime_float();
$data
=
array
();
foreach
(
$url_arr
as
$key
=>
$val
)
{
$data
[
$key
]=curl_fetch(
$val
);
}
$time_end
= microtime_float();
$time
=
$time_end
-
$time_start
;
echo
"耗时:{$time}"
;
?>
耗时:0.614秒
推荐文章
2021-01-20 18:23:14
2021-01-22 17:24:38
2021-01-25 17:06:11
2021-01-28 17:37:27
2021-02-01 17:32:55
2021-02-03 17:41:37
2021-02-05 17:23:07
2021-02-08 16:59:58
稳定
产品可用性高于99.9%贴心
全国7*24小时客服热线专业
产品经理在线技术支持快速
快速上线运营快承诺
我们选择声誉坚持
10年专注高端品质开发