【发布时间】:2013-11-04 17:34:32
【问题描述】:
想知道有没有人遇到过这个问题。
我正在调用一个运行模型(在服务器上)的 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);
}
});
UPDATE 我创建了一个测试函数(作为我的运行控制器的一部分)并在函数内设置了一个 sleep(300)。我遇到了同样的 500 错误。
但是,当我更改为 sleep(299) 时,该函数运行成功。显然,每个请求有 5 分钟的限制。
我已经更改了 php.ini 中的 *max_execution_time*。还有其他建议吗?
更新 #2 我找到了解决问题的方法。问题是因为我的 PHP 设置中没有启用“safe_mode”,所以 CodeIgniter.php 中的 PHP 超时被覆盖(第 107 行)。我正在运行 CodeIgniter 2.1.4。我希望这对其他人有帮助。 :)
【问题讨论】:
-
stackoverflow 不使用 bbcode 标记。请看Markdown Editing Help页面
-
有趣的是,如果您将鼠标悬停在代码图标上,我会看到“
”建议。 -
手动在浏览器中输入您的服务脚本以及所有必需的参数,看看您是否真的收到错误 500 - 如果是 - 服务端的问题不在附加代码中
-
另一个更新。我的 CI 2.1.3 安装仍然存在这个问题。在 CI 1.7.2 下运行它时,我没有得到这种行为。我想,问题可能出在 CI 2.1.3 Session 类上。
标签: javascript php jquery ajax codeigniter-2