想知道是否有人遇到过这个问题。
我正在调用一个 CI 控制器,该控制器运行模型(在服务器上),对于特定方案需要更长的时间(大约 5 分钟)。 问题是我在长请求后收到 500 错误,但当请求较短(大约 1 分半钟)时我没有收到任何错误。
我已经检查过的一些事情:
- CI的"csrf_protection"已关闭
- 我在 ajax 调用中设置了长时间超时 (900000)
- 我已将 PHP 中的max_execution_time设置为 900
- 我已将 IIS 中的空闲超时设置为(20 分钟)
这是我的 ajax 电话:
$.ajax({
type:'POST',
url:"run/runScenario/" + saveOrUpdate + "/" + scenarioname + "/" + units + "/" + stateid + "/" + climatestationid + "/" + soiltexture + "/" +
moisturecontent + "/" + modsoilflag + "/" + slopelength + "/" + slopeshape + "/" + slopesteepness + "/" + vegcommunity + "/" +
basalcover + "/" + canopycover + "/" + rockcover + "/" + littercover + "/" + cryptogamscover,
data: {scenarioDescription: scenariodescription},
timeout:900000,
statusCode: {
500: function() {
alert( "page not found" );
}
},
success: function(runData){
$('#progressBar').append('<p>Done running scenario.</p>');
$('#progressBar').append('<p>Saving scenario...</p>');
saveScenarioResultsTable();
$('#progressBar').append('<p>Creating output table...</p>');
printScenarioResultsTable(scenarioname);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
// stop timer
var end = new Date().getTime();
var execution_time = end - TIMER;
runTimeMessage = "<br/><b>Ran scenario in " + (parseInt(execution_time) * 0.001) + " seconds.</b>";
alert(runTimeMessage);
}
});
更新 我创建了一个测试函数(作为运行控制器的一部分)并在函数内设置了一个 sleep(300)。 我得到了同样的 500 错误。
但是,当我更改为 sleep(299) 时,函数运行成功。 显然,每个请求有 5 分钟的限制。
我已经更改了 php.ini 中的 *max_execution_time*。 还有其他建议吗?
更新#2我已经找到了解决问题的方法。问题是,由于在我的PHP设置中未启用"safe_mode",因此PHP超时在CodeIgniter中被覆盖.php(第107行)。我正在运行CodeIgniter 2.1.4。我希望这对其他人有所帮助。:)
只是一个想法,但不是代码的修复:
如果您将使用两个不同的 ajax 请求,该怎么办:
- 请求在某个缓冲区(如文件或 sql 记录)中处理和写入处理结果。此请求可能会也可能不会返回未来资源的随机描述符。
- 请求通过描述符或仅通过资源的可用性获取处理结果。此请求必须加入计时器。
时间轴:
-------------------------------------------------------------------
Step Local server processing
-------------------------------------------------------------------
1. Request for processing >>> Server >>> Thread for processing
2. Descriptor of resource <<< Server >>> Descriptor of resource
3. Server <<< Result of processing
4. Request by descriptor >>> Server
5. Result <<< Server >>> Deletion of file or record
-------------------------------------------------------------------
那里:
1, 2 - Ajax #1,按需触发.
4, 5 - Ajax #2,每 10 秒发射一次。