gpt4 book ai didi

php - AJAX 上传 - 在继续之前不等待响应

转载 作者:可可西里 更新时间:2023-11-01 12:59:13 26 4
gpt4 key购买 nike

我正在使用 Blueimp's jQuery Uploader (非常好,顺便说一句)和一个 S3 处理程序来上传文件,然后通过 S3 API(来自 PHP SDK)将它们传输到 S3。

它有效。问题是,在 文件 (>1GB) 上,传输(通过创建对象)到 S3 最多可能需要 几分钟。执行此操作的 PHP 文件将挂起,直到此过程完成。问题是, uploader (使用 jQuery Ajax method )似乎每次都放弃等待并重新开始。

我认为这与 PHP INI 'max_input_time' 等有关,因为它似乎等待了大约 60 秒,尽管现在看起来有所不同。我已经提高了 PHP INI 和其他相关的 max_input_time - 但没有进一步提高。

我还考虑过(更有可能)JS,无论是在脚本中还是在 jQuery 方法中都有超时。开发人员 (blueimp) 表示在前端脚本中没有这样的超时,我也没有看到任何超时,尽管在 jQuery Ajax 方法选项中引用了“超时”,但它似乎影响了上传的整个时间而不是等待以获得回应 - 所以这没什么用。

感谢收到的任何帮助或指导。

最佳答案

jQuery 文档位于 http://api.jquery.com/jQuery.ajax/说:

timeout

Set a timeout (in milliseconds) for the request. This will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the $.ajax call is made; if several other requests are in progress and the browser has no connections available, it is possible for a request to time out before it can be sent. In jQuery 1.4.x and below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be cancelled by a timeout; the script will run even if it arrives after the timeout period.

除此之外,检查 php set_time_limit 函数和 php max 内存设置也是一个好主意。

无论如何,在我看来最好的方法是像这样实现错误回调

$.ajax('yourScript.php',{
error:function(jqXHR){ echo this error ... }
});

jQuery 文档说:

error callbacks are invoked, in the order they are registered, if the request fails. They receive the jqXHR, a string indicating the error type, and an exception object if applicable. Some built-in errors will provide a string as the exception object: "abort", "timeout", "No Transport".

这可能会提示您是谁(服务器或客户端)停止了传输。

希望对你有帮助

关于php - AJAX 上传 - 在继续之前不等待响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com