XHR запрос $ .Ajax занимает много времени, чтобы ответить через некоторое время

Я знаю, что это, возможно, сообщается как дублированный, но я потерял много времени (3 недели), копаясь в Интернете везде, пытаясь найти решение ..

Я работаю на заявка на которые позволяют мне заставить агентов работать над этим .. и когда я запускаю свое приложение, у меня возникла проблема, которая Остановился так долго, что после долгих поисков я понял, что мне нужно закрывать сессии, используя session_write_close(); после того, как я положил в него свои данные.

сейчас у меня другая ситуация, тот же файл занимает около 2 сек. во-первых, я устанавливаю свое приложение на свой сервер «локальный сервер, CentOS».
введите описание изображения здесь

сейчас и через 2 или 3 недели это занимает 20 сек !!! и я не знаю почему? !!!
введите описание изображения здесь

  • вот мой код Ajax:

.

$("#totagentdetails").click(function () {
$("#modal-body").html("");
var queue = $("#queue").val();

$.ajax({
type:'POST',
url:'getdetails.php',
data: {"queue":queue, "asker":"totagents"},
dataType: 'json',
success: function(response){
if(response.res != "error"){
$("#modal-title").html("Total agents details:");
$("#modal-body").html(response.tbldetails);
}else{
var result = response.msg;
alert(result);
}
}
});

});

и вот код «getdetails.php»:

<?php
session_start();
session_write_close();
include_once("../functions/main_config.php");
include_once("../functions/function_mrh.php");
include_once("../functions/enc_dec.php");
include('../phpseclib1.0.9/Net/SSH2.php');

$queue = $_POST['queue'];
$asker = $_POST['asker'];

date_default_timezone_set("Africa/Cairo");

switch ($asker) {
case "totagents":
case "readyagents":
case "hascalls":
case "waitingcalls":
case "breaks":
$command = '/usr/sbin/asterisk -rx "queue show  '.$queue.'"';
break;

default:
$command = "error!";
}

$connection = ssh2_connect($sip_host, 22);
ssh2_auth_password($connection,$sip_user,$sip_pass);
$stream = ssh2_exec($connection,$command);
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
$output = rtrim($output);
$output  = explode("\n", $output );


switch ($asker) {
case "totagents":
$finalRes = "<table class='table table-striped table-bordered table-hover'>
<thead>
<tr>
<th>Agent name</th>
<th>Extension</th>
<th>Status</th>
<th>Num. of calls</th>
<th>Total sign in</th>
</tr>
</thead>
<tbody>

";


foreach($output as $key=>$value) {
if ($key > 1){
if (trim($value) == "No Callers"){
break;
} elseif (trim($value) == "Callers:"){
break;
}else{

@list($agentName, $restOfTheLine) = explode("(SIP/", $value);
$finalRes .= "<tr><td>".trim($agentName) ."</td>";

@list($Ext, $restOfTheLine) = explode("from", $restOfTheLine);
$finalRes .= "<td>".trim($Ext) ."</td>";

@list($stat, $restOfTheLine) = explode(") has", $restOfTheLine);
// get break type if it == "paused) (N"if (strpos(mb_substr($stat, 42, 10), 'paused') !== false) {
$dbh6 = @mysql_connect($app_host, $app_user, $app_pass) or die ("error in host-log connection");
@mysql_select_db($log_database, $dbh6) or die("error in agentsaction database selections");

$qry = "select status from ".$log_database.".livecounter where ext='".trim($Ext)."';";
$result = mysql_query($qry);
if($result){
$row = mysql_fetch_array($result);
$stat = $row['status'];
include_once("../functions/closelogdb_mrh.php");
} else {
$stat = "paused";
}
} else {
$stat = mb_substr($stat, 42, 10);
if(trim($stat) == "Unavailabl"){$stat = "Unavailable";}
if(trim($stat) == "Not in use"){$stat = "Ready";}
}


$finalRes .= "<td>".trim($stat)."</td>";

@list($hasTake, $restOfTheLine) = explode("taken", $restOfTheLine);
$hasTake = mb_substr($restOfTheLine, 0, 3);
if (trim($hasTake) == "no"){$hasTake = 0;}

$finalRes .= "<td>".trim($hasTake)."</td>";


//calc inqueuetot from database

$dbh6 = @mysql_connect($app_host, $app_user, $app_pass) or die ("error in host-log connection");
@mysql_select_db($log_database, $dbh6) or die("error in agentsaction database selections");

$qry = "select * from ".$log_database.".livecounter where ext='".trim($Ext)."';";
$result = mysql_query($qry);
if($result){
$row = mysql_fetch_array($result);
$logdatetime = $row['logdatetime'];
$current_datetime = date('Y-m-d H:i:s');
$alllogTime = subTwoDates_2from1($current_datetime, $logdatetime);
} else {
$alllogTime = "N/A";
}

$finalRes .= "<td>".$alllogTime."</td></tr>";
}
}
}


$finalRes .= "</tbody>
</table>
";
break;

default:
$command = "error!";
}



echo json_encode(array("res" => "greatJob", "msg" => $output, "tbldetails" => $finalRes));


?>

ОБНОВЛЕНИЕ 1:

интересный комментарий от @RamRaider, но я многого не понял, набрал факел: // нетто-Внутрикорпусные / # события в адресной строке, то я нажал на URL_REQUEST для файла «getdetails.php», и он загружает кучу данных:

194691: URL_REQUEST
https://10.1.80.7/cc/supervisor/getdetails.php
Start Time: 2018-03-04 13:06:35.765

t=559792 [st=    0] +REQUEST_ALIVE  [dt=20486]
--> priority = "MEDIUM"--> url = "https://10.1.80.7/cc/supervisor/getdetails.php"t=559793 [st=    1]   +URL_REQUEST_DELEGATE  [dt=6]
t=559793 [st=    1]      DELEGATE_INFO  [dt=4]
--> delegate_blocked_by = "extension IDM Integration Module"t=559798 [st=    6]      DELEGATE_INFO  [dt=1]
--> delegate_blocked_by = "extension AdGuard AdBlocker"t=559799 [st=    7]   -URL_REQUEST_DELEGATE
t=559799 [st=    7]   +URL_REQUEST_START_JOB  [dt=20466]
--> load_flags = 33024 (MAYBE_USER_GESTURE | VERIFY_EV_CERT)
--> method = "POST"--> upload_id = "0"--> url = "https://10.1.80.7/cc/supervisor/getdetails.php"t=559799 [st=    7]     +URL_REQUEST_DELEGATE  [dt=4]
t=559799 [st=    7]        DELEGATE_INFO  [dt=2]
--> delegate_blocked_by = "extension IDM Integration Module"t=559801 [st=    9]        DELEGATE_INFO  [dt=2]
--> delegate_blocked_by = "extension IDM Integration Module"t=559803 [st=   11]     -URL_REQUEST_DELEGATE
t=559803 [st=   11]      HTTP_CACHE_GET_BACKEND  [dt=0]
t=559803 [st=   11]     +HTTP_STREAM_REQUEST  [dt=96]
t=559803 [st=   11]        HTTP_STREAM_REQUEST_STARTED_JOB
--> source_dependency = 194693 (HTTP_STREAM_JOB)
t=559899 [st=  107]        HTTP_STREAM_REQUEST_BOUND_TO_JOB
--> source_dependency = 194693 (HTTP_STREAM_JOB)
t=559899 [st=  107]     -HTTP_STREAM_REQUEST
t=559900 [st=  108]      URL_REQUEST_DELEGATE  [dt=0]
t=559900 [st=  108]     +HTTP_STREAM_REQUEST  [dt=68]
t=559900 [st=  108]        HTTP_STREAM_REQUEST_STARTED_JOB
--> source_dependency = 194697 (HTTP_STREAM_JOB)
t=559968 [st=  176]        HTTP_STREAM_REQUEST_BOUND_TO_JOB
--> source_dependency = 194697 (HTTP_STREAM_JOB)
t=559968 [st=  176]     -HTTP_STREAM_REQUEST
t=559968 [st=  176]     +UPLOAD_DATA_STREAM_INIT  [dt=0]
t=559968 [st=  176]        UPLOAD_DATA_STREAM_INIT  [dt=0]
--> is_chunked = false
--> net_error = 0 (?)
--> total_size = 23
t=559968 [st=  176]     -UPLOAD_DATA_STREAM_INIT
--> is_chunked = false
--> net_error = 0 (?)
--> total_size = 23
t=559968 [st=  176]     +HTTP_TRANSACTION_SEND_REQUEST  [dt=1]
t=559968 [st=  176]        HTTP_TRANSACTION_SEND_REQUEST_HEADERS
--> POST /cc/supervisor/getdetails.php HTTP/1.1
Host: 10.1.80.7
Connection: keep-alive
Content-Length: 23
Accept: application/json, text/javascript, */*; q=0.01
Origin: https://10.1.80.7
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.0.12335 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
DNT: 1
Referer: https://10.1.80.7/cc/supervisor/index.php
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8,ar;q=0.6
Cookie: [36 bytes were stripped]
t=559968 [st=  176]        HTTP_TRANSACTION_SEND_REQUEST_BODY
--> did_merge = false
--> is_chunked = false
--> length = 23
t=559968 [st=  176]       +UPLOAD_DATA_STREAM_READ  [dt=0]
--> current_position = 0
t=559968 [st=  176]          UPLOAD_DATA_STREAM_READ  [dt=0]
--> current_position = 0
t=559968 [st=  176]       -UPLOAD_DATA_STREAM_READ
t=559969 [st=  177]        UPLOAD_DATA_STREAM_READ  [dt=0]
--> current_position = 23
t=559969 [st=  177]     -HTTP_TRANSACTION_SEND_REQUEST
t=559969 [st=  177]     +HTTP_TRANSACTION_READ_HEADERS  [dt=20288]
t=559969 [st=  177]        HTTP_STREAM_PARSER_READ_HEADERS  [dt=20288]
t=580257 [st=20465]        HTTP_TRANSACTION_READ_RESPONSE_HEADERS
--> HTTP/1.1 200 OK
Date: Sun, 04 Mar 2018 11:06:29 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
X-Powered-By: PHP/5.4.16
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
t=580257 [st=20465]     -HTTP_TRANSACTION_READ_HEADERS
t=580257 [st=20465]     +URL_REQUEST_DELEGATE  [dt=8]
t=580257 [st=20465]        DELEGATE_INFO  [dt=5]
--> delegate_blocked_by = "extension IDM Integration Module"t=580262 [st=20470]        DELEGATE_INFO  [dt=3]
--> delegate_blocked_by = "extension AdGuard AdBlocker"t=580265 [st=20473]     -URL_REQUEST_DELEGATE
t=580265 [st=20473]   -URL_REQUEST_START_JOB
t=580265 [st=20473]    URL_REQUEST_DELEGATE  [dt=1]
t=580266 [st=20474]    HTTP_TRANSACTION_READ_BODY  [dt=11]
t=580277 [st=20485]    URL_REQUEST_JOB_FILTERED_BYTES_READ
--> byte_count = 9775
t=580278 [st=20486]    HTTP_TRANSACTION_READ_BODY  [dt=0]
t=580278 [st=20486]    URL_REQUEST_JOB_FILTERED_BYTES_READ
--> byte_count = 1
t=580278 [st=20486]    HTTP_TRANSACTION_READ_BODY  [dt=0]
t=580278 [st=20486] -REQUEST_ALIVE

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]