开发者

How do I kill a session in Symfony2?

It appears that Sym开发者_如何学运维fony2 is waiting for AJAX response after a request. It will not go to another link on the same page until the response comes back.

This article describes the problem: http://garethmccumskey.blogspot.com/2009/10/php-session-write-locking-and-how-to.html

I cannot find a solution in Symfony2 though.


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.

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.

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.

Regards,
Matt


Just a warning for those who are using the PHP built-in web server (as I got trapped, it might help others):

From the PHP doc:

The web server runs a only one single-threaded process, so PHP applications will stall if a request is blocked.

It means that even if you close the session properly, you'll still end up stailing with one connection at once.

http://php.net/manual/en/features.commandline.webserver.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜