From e1b9665567bbfc28bb13e5e41093901a8da99a0d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 2 Jun 2014 10:09:56 +0300 Subject: Fix Session_database_driver locking Ref: #3073 --- .../Session/drivers/Session_database_driver.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'system/libraries/Session/drivers/Session_database_driver.php') diff --git a/system/libraries/Session/drivers/Session_database_driver.php b/system/libraries/Session/drivers/Session_database_driver.php index 24847456c..2bdc4d0d5 100644 --- a/system/libraries/Session/drivers/Session_database_driver.php +++ b/system/libraries/Session/drivers/Session_database_driver.php @@ -116,15 +116,15 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan $db_driver = $this->_db->dbdriver.(empty($this->_db->subdriver) ? '' : '_'.$this->_db->subdriver); if (strpos($db_driver, 'mysql') !== FALSE) { - $this->_lock_type = 'mysql'; + $this->_lock_driver = 'mysql'; } elseif (in_array($db_driver, array('postgre', 'pdo_pgsql'), TRUE)) { - $this->_lock_type = 'postgre'; + $this->_lock_driver = 'postgre'; } elseif (extension_loaded('sysvsem')) { - $this->_lock_type = 'semaphore'; + $this->_lock_driver = 'semaphore'; } isset($this->_table) OR $this->_table = config_item('sess_table_name'); @@ -248,18 +248,20 @@ class CI_Session_database_driver extends CI_Session_driver implements SessionHan protected function _get_lock() { - $arg = $this->_session_id - .($this->_match_ip ? '_'.$_SERVER['REMOTE_ADDR'] : ''); - if ($this->_lock_driver === 'mysql') { + $arg = $this->_session_id + .($this->_match_ip ? '_'.$_SERVER['REMOTE_ADDR'] : ''); return (bool) $this->_db - ->query("SELECT GET_LOCK('".$session_id."', 10) AS ci_session_lock") + ->query("SELECT GET_LOCK('".$arg."', 10) AS ci_session_lock") ->row() ->ci_session_lock; } elseif ($this->_lock_driver === 'postgre') { + $arg = "hashtext('".$this->_session_id."')" + .($this->_match_ip ? ", hashtext('".$_SERVER['REMOTE_ADDR']."')" : ''); + return (bool) $this->_db->simple_query('SELECT pg_advisory_lock('.$arg.')'); } elseif ($this->_lock_driver === 'semaphore') -- cgit v1.2.3-24-g4f1b