长时间的呼叫 - 如何避免网络超时
在一个网络应用程序中,我对多个长时间运行的 php 脚本进行了一些 ajax 调用(用户等待是可以的)。不过,为了安全起见,我将在服务器前面添加 AWS cloudfront,这将导致 180 秒(允许的最大值)后超时。
我需要实现一种机制来在服务器端运行长脚本并轮询浏览器的结果。 一种选择是:
On the server side:
We create a script 'async_call' which receives the file to call in addition to the url params and does the following:
1 - calc hash for the the call (used for storing/getting apc info for this call)
2 - if status in apc value indicates not running
2.1 - Store in call-status-APC-<hash> the call status as running
2.2 - Call the script file using curl with params and cookies without timeout
2.3 - when the data returns store it in return-value-APC-<hash> and return it.
3 - If the apc status indicates running
3.1 Poll for results in the return-value-APC-<hash> every few seconds and if exist delete and return it.
On the client side:
Ajax has retry functionality so if it times out it will call again. so:
1 - change from calling ajax_file.php -> async_call?file=ajax_file.php&all-other-params
2- set ajax retry (e.g. 10)
是否有更优雅的方法来做到这一点?
In a web app I have some ajax calls to multiple long running php scripts (its OK that the user will wait). However I'm about to add AWS cloudfront in front of the server for security which will cause timeout after 180sec (its the maximum allowed).
I need to implement a mechanism to run the long scripts on the server side and poll the results from the browser.
One option is :
On the server side:
We create a script 'async_call' which receives the file to call in addition to the url params and does the following:
1 - calc hash for the the call (used for storing/getting apc info for this call)
2 - if status in apc value indicates not running
2.1 - Store in call-status-APC-<hash> the call status as running
2.2 - Call the script file using curl with params and cookies without timeout
2.3 - when the data returns store it in return-value-APC-<hash> and return it.
3 - If the apc status indicates running
3.1 Poll for results in the return-value-APC-<hash> every few seconds and if exist delete and return it.
On the client side:
Ajax has retry functionality so if it times out it will call again. so:
1 - change from calling ajax_file.php -> async_call?file=ajax_file.php&all-other-params
2- set ajax retry (e.g. 10)
Is there a more elegant way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论