我正在做的是当页面加载时我调用两个ajax请求
fetch_list_big();
fetch_list_small();
function fetch_list_big(){
$.post(...);
}
function fetch_list_small(){
$.post(...);
}
顾名思义,fetch_list_big()
中的请求比 fetch_list_small
需要更多时间才能完成。
但由于 fetch_list_big
首先被调用,fetch_list_small
表示待处理,直到 fetch_list_big
返回 200。
big.php
require_once('files_same.php'); #starts session /connection / configurations etc
#Some heavy mysql stuff #say 5 seconds
echo json(...)
小.php
require_once('files_same.php'); #starts session /connection / configurations etc
#Some light mysql stuff #say 1 seconds
echo json(...)
如何在 fetch_list_big()
之后并行调用 fetch_list_small()
并且不使其挂起?
待处理请求
第一个请求很大,在服务器中花费了 5 秒
最后 3 个是小请求,应该在第一个请求之前返回,但它们正在等待处理。
第一个请求返回 200 后
第一个请求返回 200 后。最后 3 个请求被执行。
问题
我希望所有请求并行运行而不锁定服务器(是否有某种 session 被锁定?)
最佳答案
I want all the requests to Run Parallel without locking in server (is some kind of session is getting locked ? )
是的;只要一个脚本实例正在使用该 session ,PHP 就会阻止其他脚本访问该 session 。 (至少对于默认的基于文件的 session 存储机制是这样。)
您可以通过调用session_write_close来避免这种情况一旦您的脚本完成了 session 所需的操作。
关于javascript - ajax 请求正在等待并行请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41825485/