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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.