현재 'sniffer.php'라는 단일 PHP 파일을 호출하려고합니다. JavaScript 파일을 사용하여 비동기로 작업하고 있습니다. 내가 현재 가지고있는 문제는 PHP 코드에서 무작위로 절전 기능을 추가 한 것입니다 (페이지가로드되는 것처럼 작동합니다). 그 문제는 두 개 이상의 함수가 페이지를 호출하여 페이지 중 하나가 먼저 완료된 다음 다른 요청이 중지 될 때까지 계속 기다립니다. EG : 5 초 동안 잠을 자고 다른 하나는 6 초 동안 잔다. 첫 번째 작업은 5 초 후에 완료되고 다음 작업은 11 초에 완료됩니다. 내가 찾고있는 것은 5 초 안에 완료되고 다음은 1 초 후에 완료된다는 것입니다. 문제가 발생하는 '잠자기'인지 또는 파일이 잠자기로 인해 잠겨 있는지 확실하지 않습니다.단일 파일에 대한 다중 HTTP 요청
도움/의견을 보내 주셔서 감사합니다.
내 PHP 파일은 다음과 같습니다
$c = rand(2,10);
sleep($c);
$html .= $c;
echo json_encode(array('html'=>$html,'status'=>1));
exit;
내 자바 스크립트 클래스는 다음과 같습니다
var path = '/';
var polling = {
add : function(name, obj) {
this[name] = new xAjax(obj);
return this;
}
};
function xAjax(options) {
var consti = {
};
var defaults = {
url: path + 'sniffer.php',
method: 'POST',
responseType: 'json',
async: true,
timeout: 30000,
success: function(response) {console.log(response);},
done: function() {},
beforeSend: function() {},
error: function(e) {console.log(e);},
abort: function() {}
};
var settings = Object.assign({}, defaults, options, consti);
var xhr = null;
this.run = function() {
xhr = new XMLHttpRequest();
settings.beforeSend();
xhr.responseType = settings.responseType;
xhr.open(settings.method, settings.url, settings.async);
xhr.timeout = settings.timeout;
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200) {
settings.success(xhr.response);
} else {
settings.error(xhr.response);
}
settings.done();
xhr = null;
}
};
xhr.send();
return this;
};
this.abort = function() {
xhr.abort();
xhr = null;
settings.abort();
return this;
};
this.isRunning = function() {
return xhr != null;
};
this.set = function(options) {
settings = Object.assign({}, defaults, options, consti);
return this;
};
}
내 생성 /를 sniffer.php에 전화 :
polling.add('x');
polling.x.run();
polling.add('y');
polling.y.run();
PHP 세션은 동시 요청을 잠급니다. PHP 코드에서 세션을 시작했는지 확인하십시오. – jorgonor
슬립은 현재 요청뿐만 아니라 현재 세션에 대한 실행을 지연시킵니다. – ADyson
당신 말이 맞아요. 나는 세션을 시작했다. 나는 그것을 우회하는 방법이 없다고 가정합니다. 그것이 수면 (EG SQL 프로세스) 이외의 것이라면 여전히 세션 잠금이됩니까? – Deadweight