Skip to content

Commit 2178c32

Browse files
authored
Merge pull request #139 from issei-m/fix-session-data-lost
Fix session data losing under certain situation
2 parents 6e0cccb + 2dbac2f commit 2178c32

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

lib/response/sfWebResponse.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ public function send()
398398

399399
if (function_exists('fastcgi_finish_request'))
400400
{
401+
$this->dispatcher->notify(new sfEvent($this, 'response.fastcgi_finish_request'));
401402
fastcgi_finish_request();
402403
}
403404
}

lib/util/sfContext.class.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class sfContext implements ArrayAccess
2727
$configuration = null,
2828
$mailerConfiguration = array(),
2929
$serviceContainerConfiguration = array(),
30-
$factories = array();
30+
$factories = array(),
31+
$hasShutdownUserAndStorage = false;
3132

3233
protected static
3334
$instances = array(),
@@ -87,6 +88,7 @@ public function initialize(sfApplicationConfiguration $configuration)
8788
}
8889

8990
$this->dispatcher->connect('template.filter_parameters', array($this, 'filterTemplateParameters'));
91+
$this->dispatcher->connect('response.fastcgi_finish_request', array($this, 'shutdownUserAndStorage'));
9092

9193
// register our shutdown function
9294
register_shutdown_function(array($this, 'shutdown'));
@@ -592,6 +594,22 @@ public function filterTemplateParameters(sfEvent $event, $parameters)
592594
return $parameters;
593595
}
594596

597+
/**
598+
* Shuts the user/storage down.
599+
*
600+
* @internal Should be called only via invoking "response.fastcgi_finish_request" or context shutting down.
601+
*/
602+
public function shutdownUserAndStorage()
603+
{
604+
if (!$this->hasShutdownUserAndStorage && $this->has('user'))
605+
{
606+
$this->getUser()->shutdown();
607+
$this->getStorage()->shutdown();
608+
609+
$this->hasShutdownUserAndStorage = true;
610+
}
611+
}
612+
595613
/**
596614
* Calls methods defined via sfEventDispatcher.
597615
*
@@ -635,12 +653,7 @@ public function __call($method, $arguments)
635653
*/
636654
public function shutdown()
637655
{
638-
// shutdown all factories
639-
if($this->has('user'))
640-
{
641-
$this->getUser()->shutdown();
642-
$this->getStorage()->shutdown();
643-
}
656+
$this->shutdownUserAndStorage();
644657

645658
if ($this->has('routing'))
646659
{

0 commit comments

Comments
 (0)