Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
637 views
in Technique[技术] by (71.8m points)

symfony - How do I kill a session in Symfony2?

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...