Skip to content

Commit

Permalink
Use destructor to close session (partially reverted #348) (#412)
Browse files Browse the repository at this point in the history
* Use destructor to shutdown session (partially reverted #348)

* Register shutdown function only if session locking is enabled
  • Loading branch information
supersmile2009 authored and curry684 committed Apr 18, 2018
1 parent 5fca27f commit ae3a607
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Session/Storage/Handler/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public function __construct($redis, array $options = array(), $prefix = 'session
$this->lockMaxWait = self::DEFAULT_MAX_EXECUTION_TIME;
}

register_shutdown_function(array($this, 'shutdown'));
if (true === $locking) {
register_shutdown_function(array($this, 'shutdown'));
}
}

/**
Expand Down Expand Up @@ -270,7 +272,16 @@ protected function getRedisKey($key)
/**
* Shutdown handler, replacement for class destructor as it might not be called.
*/
public function shutdown() {
public function shutdown()
{
$this->close();
}

/**
* Destructor.
*/
public function __destruct()
{
$this->shutdown();
}
}

0 comments on commit ae3a607

Please sign in to comment.