How to kill a session in symfony2?

It seems like Symfony2 is waiting for an AJAX response after the request. He will not go to another link on the same page until the answer returns.

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

I can't find a solution in Symfony2 though.

+5
source share
2 answers

After reading the blog post, you refer to the code for the Session and NativeSessionStorage and read the code that I would like to try to simulate the behavior mentioned in the blog post to do this:

 $session = $this->get('session'); // Change the session attributes $session->save(); session_write_close(); // Do database calls and other stuff. 

I have not tested it, but it should work properly. Another solution to your problem is to use a different session store than NativeSessionStorage , which is the default. You can use, for example, database storage using the PdoSessionStorage object. This may prevent the lock from using PHP. For more information on how to use the database store for sessions, see the cookbook entry .

But there is no guarantee that the database system will not add up multiple queries if they access the same row, but it should be faster than with NativeSessionStorage .

Respectfully,
Matt

+14
source

Just a warning to anyone using the PHP built-in web server (since I got trapped, this might help others):

From a PHP document:

The web server starts only one single-threaded process, so PHP applications will stop if the request is blocked.

This means that even if you close the session correctly, you will still encounter one connection at once.

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

+1
source

All Articles