[英]How to print page load time only once
enter code here
$loadMessageDisplayed = FALSE;
function file_get_contents_curl($url){
global $loadMessageDisplayed;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
//PAGE LOAD TIME
if(!curl_errno($ch) && !$loadMessageDisplayed){
$cinfo = curl_getinfo($ch);
echo 'Page loaded in '.$cinfo['total_time'].' seconds';
$loadMessageDisplayed = TRUE;
}
curl_close($ch);
return $data;
}
I want to display page load time only once.我只想显示一次页面加载时间。 Again if i call the same function it should not display me load time.同样,如果我调用相同的函数,它不应该显示我的加载时间。
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
//PAGE LOAD TIME
if (!defined('constant')) {
define('constant', 'value');
if (!curl_errno($ch)) {
$cinfo = curl_getinfo($ch);
echo 'Page loaded in ' . $cinfo['total_time'] . ' seconds';
}
}
curl_close($ch);
return $data;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.