我在Windows 2012上使用Apache版本(httpd-2.4.10-win64-VC11)。我試圖在點擊圖片項目它會打開關於這個項目的信息對話。我這樣做:等待時間(TTFB)大於4秒結果來自`get_headers()`
var self = $(this),
vaid = "1",
btnhref = self.attr('href'),
itemID = getVar("item",btnhref);
$.ajax({
type: 'POST',
url: '/action.php',
data: {"itemID" : itemID},
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('va', vaid);
},
statusCode: {
401:function() { Validation('401 Unauthorized</br>Error: Invalid Action'); }
},
complete: function()
{
var state = {
"dialog": true
};
history.pushState(state, document.title, btnhref);
},
success: function(response){},
cache: true,
contentType: "application/x-www-form-urlencoded",
processData: true
});
問題是響應非常緩慢,我無法找到它的原因。下面我添加我從鉻速度追蹤器收到的數據。
P.S:我正在使用cloudfront的圖像,CSS & Javascripts文件。
http://i.stack.imgur.com/UEh2Q.png
編輯:這個細節從提琴手Web調試:(用GET或POST相同的結果)
==時序信息============
ClientConnected:13:53:10.037
ClientBeginRequest:13:53:10.064
GotRequestHeaders:13:53:10.064
ClientDoneRequest:13:53:10.064
確定網關:0毫秒
DNS查找:1毫秒
TCP/IP連接:16ms的
HTTPS握手:0ms
ServerConnected:13:53:10.080
FiddlerBeginRequest:13:53:10.080
ServerGotRequest:13:53:10.080
ServerBeginResponse:13:53:10.593
GotResponseHeaders:13:53:10.593
ServerDoneResponse:13 :53:15.366
ClientBeginResponse:13:53:15.366
ClientDoneResponse:13:53:15。366
Apache Log:LogFormat「%h%l%u%t \」%r \「%> s%b \」%{Referer} i \「\」%{User-Agent} i \「 「組合
37.8.80.203 - - [04/Apr/2015:11:06:13 +0000] "GET /shadiCo/item/146 HTTP/1.1" 200 33640 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
37.8.80.203 - - [04/Apr/2015:11:06:20 +0000] "POST /method/pusher HTTP/1.1" 200 96 "http://localhost/shadiCo/item/146" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
37.8.80.203 - - [04/Apr/2015:11:06:20 +0000] "POST /method/pusher HTTP/1.1" 200 96 "http://localhost/shadiCo/item/146" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36"
後使用@elcodedocle代碼編輯: 問題不阿賈克斯或MySQL問題,其get_headers()函數問題它們會減慢,我使用的檢查,如果圖像的存在與否,由請求使用此功能:
public function url_exists($url) {
if(!empty($url) && $this->is_url($url) && extension_loaded('openssl'))
{
$file_headers = get_headers($url);
if($file_headers[0] == 'HTTP/1.1 404 Not Found')
{
return false;
}else{
$allowed = array('Content-Type: image/jpeg','Content-Type: image/pjpeg','Content-Type: image/png','Content-Type: image/gif');
if(!in_array($file_headers[1], $allowed))
{
return false;
}else{
return true;
}
}
}else{
return false;
}
}
嘗試使用GET而不是POST – 2015-04-04 10:42:27
可以從apache發送日誌嗎?我的意思是 - 你確定,它是ajax慢? – Legendary 2015-04-04 10:45:16
這可能是服務器配置錯誤(hosts文件,DNS conf,路由表,apache虛擬主機......類似的東西)。需要服務器日誌爲action.php POST ajax請求,否則它只是盲目猜測。 – NotGaeL 2015-04-04 11:03:16