2015-12-03 70 views

回答

2

您可以在PHP捲曲的幫助下簡單地做。您可以發送請求並查看確切的請求時間。

<?php 
    if(!isset($_GET['url'])) 
    die("enter url"); 
    $ch = curl_init($_GET['url']); //get url http://www.xxxx.com/cru.php?url=http://www.example.com 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    if(curl_exec($ch)) 
    { 
    $info = curl_getinfo($ch); 
    echo 'Took ' . $info['total_time'] . ' seconds to transfer a request to ' . $info['url']; 
    } 

    curl_close($ch); 
?> 
+0

非常感謝Nandu。 – user3305431

1

如果你已經擁有的網址,你可以將它們傳遞給這個函數,你會得到響應時間:

<?php 
// check responsetime for a webbserver 
function pingDomain($domain){ 
    $starttime = microtime(true); 
    // supress error messages with @ 
    $file  = @fsockopen($domain, 80, $errno, $errstr, 10); 
    $stoptime = microtime(true); 
    $status = 0; 

    if (!$file){ 
     $status = -1; // Site is down 
    } 
    else{ 
     fclose($file); 
     $status = ($stoptime - $starttime) * 1000; 
     $status = floor($status); 
    } 
    return $status; 
} 
?> 

http://tech.fireflake.com/2008/09/17/using-php-to-check-response-time-of-http-server/

+0

始終爲-1的狀態。 – user3305431