0
您好我正在努力實現與PHP和jQuery的彗星。每個頁面加載都會啓動彗星。然而,它導致加載網站中的任何頁面變得非常緩慢,如10秒鐘,它似乎等待先前的請求到服務器die()在if($ elapse> 10) 但如果ajax連接連接是中止,是不是PHP應該停止執行furher?任何想法爲什麼重新加載頁面變得緩慢?PHP Comet導致頁面重新加載緩慢
function getPendingCheckin()
{
ignore_user_abort(false);
$iCreatedDate = $this->input->post("iLastCreateDate");
$aCheckin = [];
$prev = time();
while(! $aCheckin)
{
$aCheckin = $this->getData();
if($aCheckin || connection_aborted() == 1)
{
break;
}
else
{
sleep(1);
$elapse = time() - $prev;
if($elapse > 10)
{
die();
}
}
}
header('Content-type: application/json');
echo json_encode($aCheckin);
}
的Javascript
$(window).ready(function(){
var iLastCreateDate = $('#iLastCreateDate').val();
function startGetPendingCheckin()
{
$.ajax({
type: "POST",
url: "/kc/comet/getPendingCheckin",
data: 'iLastCreateDate=' + iLastCreateDate,
error : function(msg)
{
//alert("Error get pending checkin");
},
success :function(o)
{
if(o)
{
//process data
}
startGetPendingCheckin();
}
});
}
startGetPendingCheckin();
})