如何终止 Symfony2 中的会话? [英] How do I kill a session in Symfony2?

查看:22
本文介绍了如何终止 Symfony2 中的会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Symfony2 似乎在请求之后等待 AJAX 响应.在响应返回之前,它不会转到同一页面上的另一个链接.

It appears that Symfony2 is waiting for AJAX response after a request. It will not go to another link on the same page until the response comes back.

本文描述的问题:http://garethmccumskey.blogspot.com/2009/10/php-session-write-locking-and-how-to.html

不过我在 Symfony2 中找不到解决方案.

I cannot find a solution in Symfony2 though.

推荐答案

阅读博文后,您将参考并阅读 SessionNativeSessionStorage 类的代码,我将尝试模仿博客文章中提到的行为是这样做的:

After reading the blog post you are referring to and reading the code of the Session and NativeSessionStorage classes, what I would try to mimic the behavior mentionned in the blog post is to do this:

$session = $this->get('session');

// Change the session attributes

$session->save();
session_write_close();

// Do database calls and other stuff.

我没有测试它,但它应该可以按预期工作.您的问题的另一个解决方案是使用与默认情况下使用的 NativeSessionStorage 不同的会话存储.例如,您可以通过使用 PdoSessionStorage 对象来使用数据库存储.这可能会阻止 PHP 使用锁.有关如何将数据库存储用于会议.

I didn't test it but it should work as expected. Another solution to your problem is to use a different session storage than the NativeSessionStorage which is used by default. You could use for example a database storage by using the PdoSessionStorage object. This could prevent a lock from being use by PHP. See this cookbook entry for more information on how to use a database storage for sessions.

但不能保证数据库系统在访问同一行时不会堆叠多个请求,但它应该比使用 NativeSessionStorage 快得多.

But there is no guarantee that the database system won't stack multiple requests if they are accessing the same row but it should be way faster than with the NativeSessionStorage.

问候,
马特

这篇关于如何终止 Symfony2 中的会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆