2015-09-01 58 views
-1
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; 
} 

我只想顯示頁面加載時間一次。再次,如果我調用相同的功能,它不應該顯示我加載時間。如何僅打印頁面加載時間一次

+0

你叫什麼疑問或問題? –

+0

我無法顯示在相關領域的加載時間(段劃分 - >

useer1991

+0

當你說「只有一次」你真的是隻有一次或者是一次每個會話,一旦每X MINUES或別的東西 – daker

回答

0
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; 
} 
+0

在哪裏應用此? – useer1991

+0

我修改了代碼以顯示如何使用它。 – Amarnasan

+0

仍然無法在加載時間的字段c – useer1991

相關問題