Symfony:ajax调用导致服务器对下一个查询进行排队
当服务器上的 ajax 调用花费太多时间时,我的应用程序出现问题:它将来自用户的所有其他查询排队,直到完成服务器端(我意识到取消调用客户端没有效果,用户仍然必须等待)。
这是我的测试用例:
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<a href="another-page.php">Go to another page on the same server</a>
<script type="text/javascript">
url = 'http://localserver/some-very-long-complex-query';
$.get(url);
</script>
因此,当触发 get 并单击链接后,服务器在将我带到另一个页面之前完成第一个调用的服务。我的问题是我想避免这种行为。
我在 LAMP 服务器上,我正在寻找一种方法来通知服务器用户使用诸如 connection_aborted() 之类的函数中止查询,您认为这是正确的方法吗?另外,我知道这个PHP脚本最长的部分是MySQL查询,所以即使我知道connection_aborted()可以检测到用户取消调用,我仍然需要在MySQL查询期间检查这一点...我'我不太确定 PHP 可以处理这种“事件”。
因此,如果您有更好的想法,我迫不及待地想听听。
谢谢。
更新: 经过进一步调查,我发现问题只发生在 Symfony 框架上(我省略了精确性,我的错)。看起来 Ajax 调用会锁定任何其他未来的调用。可能与控制器或路由系统有关,我正在研究它。
对于那些对这个问题感兴趣的人来说,这里是我的新测试用例: -使用 Symfony 1.4.3 的新项目,默认配置,我刚刚创建了一个应用程序和一个默认模块。 -jquery 1.4 用于 ajax 查询。
这是我的 actions.class.php (在我独特的模块中):
class defaultActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
//Do nothing
}
public function executeNewpage()
{
//Do also nothing
}
public function executeWaitingaction(){
// Wait
sleep(30);
return false;
}
}
这是我的 indexSuccess.php 模板文件:
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<a href="<?php echo url_for('default/newpage');?>">Go to another symfony action</a>
<script type="text/javascript">
url = '<?php echo url_for('default/waitingaction');?>';
$.get(url);
</script>
对于新页面模板,它不是很相关......但是有了这个,我就能够重现锁定问题我已经在我的真实应用程序上。
其他人也有同样的问题吗?
谢谢。
I've a problem with my application when an ajax call on the server takes too much time : it queue all the others queries from the user until it's done server side (I realized that canceling the call client side has no effect and the user still have to wait).
Here is my test case :
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<a href="another-page.php">Go to another page on the same server</a>
<script type="text/javascript">
url = 'http://localserver/some-very-long-complex-query';
$.get(url);
</script>
So when the get is fired and then after I click on the link, the server finish serving the first call before bringing me to the other page. My problem is that I want to avoid this behavior.
I'm on a LAMP server and I'm looking in a way to inform the server that the user aborted the query with function like connection_aborted(), do you think that's the way to go ? Also, I know that the longest part of this PHP script is a MySQL query, so even if I know that connection_aborted() can detect that the user cancel the call, I still need to check this during the MySQL query... I'm not really sure that PHP can handle this kind of "event".
So if you have any better idea, I can't wait to hear it.
Thank you.
Update :
After further investigation, I found that the problem happen only with the Symfony framework (that I omitted to precise, my bad). It seems that an Ajax call lock any other future call. It maybe related to the controller or the routing system, I'm looking into it.
Also for those interested by the problem here is my new test case :
-new project with Symfony 1.4.3, default configuration, I just created an app and a default module.
-jquery 1.4 for the ajax query.
Here is my actions.class.php (in my unique module) :
class defaultActions extends sfActions
{
public function executeIndex(sfWebRequest $request)
{
//Do nothing
}
public function executeNewpage()
{
//Do also nothing
}
public function executeWaitingaction(){
// Wait
sleep(30);
return false;
}
}
Here is my indexSuccess.php template file :
<script type="text/javascript" src="jquery-1.4.1.min.js"></script>
<a href="<?php echo url_for('default/newpage');?>">Go to another symfony action</a>
<script type="text/javascript">
url = '<?php echo url_for('default/waitingaction');?>';
$.get(url);
</script>
For the new page template, it's not very relevant... But with this, I'm able to reproduce the lock problem I've on my real application.
Is somebody else having the same issue ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是否需要在服务器上中止,或者您只想立即重定向用户?
也许像 AJAXQueue 这样的东西适合你? (对您的客户端代码进行明显的必要更改..)
Does it need to be aborted on the server, or do you just want the user redirected immediately?
Perhaps something like AJAXQueue would work for you? (with obvious required changes to your client-side code..)
好吧,我终于明白为什么应用程序正在等待:PHP 的会话系统将其他查询排队,直到会话关闭。所以我的ajax调用不需要使用会话我在我的操作花费太长时间之前执行$this->getUser()->shutdown()。
这里的每个细节: http:// garethmccumskey.blogspot.com/2009/10/php-session-write-locking-and-how-to.html
Ok, I finaly figured why the application is waiting : the session system of PHP queue the other query until session is closed. So my ajax call doesn't need to use session I do a $this->getUser()->shutdown() before my action takes too long.
Every details here : http://garethmccumskey.blogspot.com/2009/10/php-session-write-locking-and-how-to.html
你好,我有同样的问题,有类似的脚本。
Jquery 脚本
Symfony php
当页面加载时,test1 请求正在等待 usleep(10000000) 结束,但 test2 正在等待 test1 的执行结束。
我的 symfony 就遇到这个问题。
Hello i have the same problem, with a similar script.
Jquery script
Symfony php
When the page load, test1 requete is waiting the end usleep(10000000) but test2 is waiting test1's execution ending.
I have juste this problem with symfony.