2

想知道有没有人遇到过这个问题。

我正在调用一个运行模型(在服务器上)的 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”,所以 CodeIgniter.php 中的 PHP 超时被覆盖(第 107 行)。我正在运行 CodeIgniter 2.1.4。我希望这对其他人有帮助。:)

4

1 回答 1

0

就像一个想法,但不是代码的修复:

如果您将使用两个不同的 ajax 请求怎么办:

  1. 请求处理并将处理结果写入文件或sql记录等缓冲区。此请求可能会或可能不会返回未来资源的随机描述符。
  2. 请求通过描述符或仅通过资源可用性获取处理结果。此请求必须加入计时器。

时间线:

-------------------------------------------------------------------
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 秒触发一次。

于 2013-11-04T17:52:25.273 回答