简体   繁体   English

PHP ajax多次调用

[英]PHP ajax multiple calls

I have been looking for several answers around the web and here, but I could not find one that solved my problem. 我一直在网上和这里寻找几个答案,但是找不到解决我问题的答案。

I am making several JQuery ajax calls to the same PHP script. 我正在对同一PHP脚本进行多个JQuery ajax调用。 In a first place, I was seeing each call beeing executed only after the previous was done. 首先,我看到每个呼叫beeing仅在完成之前完成。 I changed this by adding session_write_close() to the beginning of the script, to prevent PHP from locking the session to the other ajax calls. 我通过在脚本的开头添加session_write_close()来更改此设置,以防止PHP将会话锁定到其他ajax调用。 I am not editing the $_SESSION variable in the script, only reading from it. 我不是在脚本中编辑$ _SESSION变量,只是从中读取。

Now the behaviour is better, but instead of having all my requests starting simultaneously, they go by block, as you can see on the image: 现在的行为更好了,但是与让我的所有请求同时开始相比,它们逐个进行了,就像您在图像上看到的那样:

请求时间表

What should I do to get all my requests starting at the same moment and actually beeing executed without any link with the other requests ? 我应该怎么做才能使我的所有请求在同一时间开始并且实际上在与其他请求没有任何链接的情况下被执行?

For better clarity, here is my js code: 为了更好的说明,这是我的js代码:

        var promises = [];
        listMenu.forEach(function(menu) {
            var res = sendMenu(menu);//AJAX CALL
            promises.push(res);
        });
        $.when.apply(null, promises).done(function() {
            $('#ajaxSpinner').hide();
            listMenu = null;
        });

My PHP script is just inserting/updating data, and start with: 我的PHP脚本只是插入/更新数据,并从以下代码开始:

<?php

session_start();
session_write_close();

//execution

I guess I am doing things the wrong way. 我想我做错事了。 Thank you in advance for you precious help !! 预先感谢您的宝贵帮助!

Thomas 汤玛士

This is probably a browser limitation, there is a maximum number of concurrent connections to a single server per browser instance. 这可能是浏览器的限制,每个浏览器实例最多可以有一个并发连接到单个服务器。 In Chrome this has been 6, which reflects the size of the blocks shown in your screenshot. 在Chrome中,该值为6,反映了屏幕截图中显示的块的大小。 Though this is from 09, I believe it's still relevant: https://bugs.chromium.org/p/chromium/issues/detail?id=12066 尽管这是从09开始的,但我认为它仍然有用: https//bugs.chromium.org/p/chromium/issues/detail?id = 12066

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM