【问题标题】:How to stop the apache server from timing out while waiting for backend script?如何在等待后端脚本时阻止 apache 服务器超时?
【发布时间】:2013-09-11 09:42:51
【问题描述】:

我有一个需要几分钟才能执行的后端脚本。我正在使用 php 前端脚本调用此后端脚本。在等待后端脚本结束之前,连接超时。我想要一个持久的后端调用,以便前端不会超时(或在certain 时间后超时)。 网页浏览器控制台抛出的错误是:

    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    Object {readyState: 4, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
      custom.js:310
    error custom.js:310
    Connection Timed Out custom.js:310
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434
    POST http:///main.php 504 (Connection Timed Out) jquery-1.8.3.js:8434

【问题讨论】:

  • 你可以使用pcntl_fork,特别是如果你不需要前端脚本的结果
  • 使用 max_execution_time

标签: php apache backend


【解决方案1】:

http://php.net/manual/en/function.set-time-limit.php

**void set_time_limit ( int $seconds )**

设置允许脚本运行的秒数。如果达到此值,脚本将返回致命错误。默认限制为 30 秒,如果存在,则为 php.ini 中定义的 ma​​x_execution_time 值。

【讨论】:

  • 实际上 php.ini 中定义的 max_execution_timemax_execution_time = 1200...仍然超时!!我什至在调用我的后端之前使用了set_time_limit(0);...没有帮助!!!
【解决方案2】:

您可能需要检查这些 PHP 函数:

ignore_user_abortset_time_limit

set_time_limit(0);         //never time out
ignore_user_abort(true);   //ignore abort

【讨论】:

    猜你喜欢
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 2019-09-10
    • 2014-04-09
    • 1970-01-01
    相关资源
    最近更新 更多