ExtJS 4 中多个同时运行的 ajax 请求
问题
我有一个长时间运行的导入作业,我从 ajax 请求开始,可能需要几分钟才能完成请求。当第一个 ajax 请求正在运行时,我想查看服务器以了解导入进行了多远,第二个请求将每 2 秒左右完成一次。
当我使用 Ext.Ajax 方法时,请求似乎被链接起来 - 第一个 ajax 请求(导入)运行直到完成,然后触发第二个(导入更新)。
我看到 Ext.Ajax 是单例的,所以也许这就是原因。因此,我尝试使用 Ext.create('Ext.data.Connection')
创建自己的 Connection 对象,但它不起作用。
我的当前请求链是:
- 第一个请求 - 开始
- 第一个请求 - 结束
- 第二个请求 - 开始
- 第二个请求 - 结束
但它应该是:
- 第一个请求 - 开始
- 第二个请求 - 开始
- 第二个request - end
- ...也许更多第二个请求
- 第一个 request - end
问题
浏览器应该能够处理多个请求,ExtJS 内部一定有限制,但我没有找到它?
更新2011-10-16
解答
问题不是ExtJS - 抱歉!它是 PHP,我的第一个脚本适用于会话,第二个脚本也尝试访问会话。由于 PHP 会话是基于文件的,会话文件从第一个请求脚本开始就被锁定,第二个请求脚本必须等到第一个请求脚本释放会话锁。
我用在每 x 行之后添加到导入过程(第一个脚本)中的这一小段代码解决了这个问题:
$id = session_id();
session_write_close();
sleep(1);
session_start($id);
因此它停止并重新加载会话,并且其他脚本能够挂钩并获取会话信息。
Problem
I have a long running import job which I start with an ajax request, it could take some minutes until the request is finished. While this first ajax request is running, I want to have a look at the server to know how far the import is gone, this second request will be done every 2 seconds or so.
When I use the Ext.Ajax
method the requests seems to be chained - the first ajax request (import) runs until it is finished, just then the second (import update) is fired.
I saw that Ext.Ajax is singleton, so maybe thats the reason. So I tried to create my own Connection objects with Ext.create('Ext.data.Connection')
but it doesn't work.
My current request chain is:
- first request - start
- first request - end
- second request - start
- second request - end
But it should be:
- first request - start
- second request - start
- second request - end
- ...maybe more second requests
- first request - end
Question
The browser should be able to handle multiple request, there must be a limitation inside ExtJS but I didn't find it?
Update 2011-10-16
Answer
The problem wasn't ExtJS - sorry! It was PHP, my first script works with the session and the second script tried to access the session as well. And because PHP sessions are file based, the session file was locked from the first request script and the second request script had to wait until the first release the session lock.
I solved this with this little piece of code I added to my import process (the first script) after every x row:
$id = session_id();
session_write_close();
sleep(1);
session_start($id);
So it stops and reloads the session and the other script was able to hook in and get the session information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单例或非单例甚至都不会改变 Ext.Ajax 的工作方式。我认为这可能是由于编码所致(您是否等待呼叫完成?)
Afaik,我以前在进行多次呼叫时从未遇到过此问题。唯一占用调用的是服务器(PHP),它不支持并行处理并导致延迟,并生成这样的模式
如果呼叫 1 需要比呼叫 2 更多的时间来处理,这可能是灾难性的。
编辑:
我已经写了 这个小演示只是为了让您感受它是如何工作的。看看吧:)花了我半个小时哈哈!
Singleton or non-singleton doesn't even change the way
Ext.Ajax
works. I think this could be due to the coding (did you wait for the calls to finish?)Afaik, I never have this problem before when I do multiple calls. The only thing that is hogging the calls is the server (PHP), which doesn't support parallel processing and causes delays, and generate a pattern like this
It could be disastrous if Call 1 requires more time to process than Call 2.
EDIT:
I have written this little demo just for you to feel how does it works. Check it out :) Spent me half an hour lol!