1
在PHP中使用microtime函數時,我似乎遇到了一個奇怪的問題。在我的index.php,我有以下返回不同結果的PHP microtime
$.ajax({
url:'loadtime.php',
datatype:"application/json",
type:'get',
data: "host=http://www.mywebsite.com",
success:function(data){
document.getElementById('loadtime_com').innerHTML = data;
},
error:function(){
// code for error
}
});
在loadtime.php
$host = $_GET['host'];
$time = microtime(TRUE);
file_get_contents($host);
$time = microtime(TRUE) - $time;
echo $time;
當去到我的index.php它表明下2.00秒的任何時間(這是錯誤的)。然後,我創建了另一個PHP文件名爲loadtime2.php,並改變了代碼
$host = "http://www.mywebsite.com";
$time = microtime(TRUE);
file_get_contents($host);
$time = microtime(TRUE) - $time;
echo $time;
然後轉到mywebsite.com/loadtime2.php測試腳本,這給了我次以上5.00秒。我找不出造成這種差異的原因,就像microtime給我時間從index.php檢索loadtime.php,而不是獲取網站內容的時間。