【问题标题】:500 error from ajax request (jQuery) to Code Igniter controller从 ajax 请求 (jQuery) 到 Code Igniter 控制器的 500 错误
【发布时间】: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


【解决方案1】:

只是一个想法,而不是对代码的修复:

如果你将使用两个不同的 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 秒触发一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2017-10-20
    • 2020-11-12
    • 2018-02-10
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多