diff --git a/framework/base/helper.class.php b/framework/base/helper.class.php index 0e5ab9fcf8..1089b8d145 100644 --- a/framework/base/helper.class.php +++ b/framework/base/helper.class.php @@ -740,6 +740,19 @@ class baseHelper session_write_close(); session_id($sessionID); + if(ini_get('session.save_handler') == 'user' and isset($_GET['tid'])) + { + $ztSessionHandler = new ztSessionHandler($_GET['tid']); + session_set_save_handler( + array($ztSessionHandler, "open"), + array($ztSessionHandler, "close"), + array($ztSessionHandler, "read"), + array($ztSessionHandler, "write"), + array($ztSessionHandler, "destroy"), + array($ztSessionHandler, "gc") + ); + register_shutdown_function('session_write_close'); + } session_start(); } diff --git a/framework/base/router.class.php b/framework/base/router.class.php index b50611fe17..7b25917551 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -3265,13 +3265,13 @@ class ztSessionHandler $sessFile = $this->getSessionFile($id); if(md5_file($sessFile) == md5($sessData)) return true; - if(file_put_contents($sessFile, $sessData)) + if(file_put_contents($sessFile, $sessData, LOCK_EX)) { - if(!file_exists($this->rawFile)) touch($this->rawFile); + touch($this->rawFile); if(strpos($sessData, 'user|') !== false) { - $rawSessContent = (string) file_get_contents($this->rawFile); - if(strpos($rawSessContent, 'user|') === false) file_put_contents($this->rawFile, $sessData); + $rawSessContent = (string) file_get_contents($this->rawFile, false, null, 0, 1024 * 2); + if(strpos($rawSessContent, 'user|') === false) file_put_contents($this->rawFile, $sessData, LOCK_EX); } return true; @@ -3290,9 +3290,10 @@ class ztSessionHandler public function destroy($id) { $sessFile = $this->getSessionFile($id); - unlink($sessFile); - unlink($this->rawFile); + if(file_exists($sessFile)) unlink($sessFile); + if(file_exists($this->rawFile)) unlink($this->rawFile); touch($sessFile); + touch($this->rawFile); return true; } diff --git a/module/cron/control.php b/module/cron/control.php index 7b863918b3..4283809823 100644 --- a/module/cron/control.php +++ b/module/cron/control.php @@ -186,7 +186,7 @@ class cron extends control /* Skip cron that status is running and run time is less than max. */ if($cronInfo->status == 'running' and (time() - strtotime($cronInfo->lastTime)) < $this->config->cron->maxRunTime) continue; /* Skip cron that last time is more than this cron time. */ - if ('cli' === PHP_SAPI) + if('cli' === PHP_SAPI) { if($cronInfo->lastTime >= $cron['time']->format(DT_DATETIME1)) continue; } @@ -197,10 +197,7 @@ class cron extends control if($now > $cron['time']) { - if (!$this->cron->changeStatusRunning($id, $cronInfo->lastTime)) - { - continue; - } + if(!$this->cron->changeStatusRunning($id, $cronInfo->lastTime)) continue; $parsedCrons[$id]['time'] = $cron['cron']->getNextRunDate(); /* Execution command. */ @@ -259,5 +256,4 @@ class cron extends control /* Revert cron status to stop. */ $this->cron->markCronStatus('stop', $configID); } - } diff --git a/module/cron/model.php b/module/cron/model.php index ef1ec7a580..1b1db8be3d 100644 --- a/module/cron/model.php +++ b/module/cron/model.php @@ -98,21 +98,16 @@ class cronModel extends model * Change cron status to running * * @param int $cronID - * @param string $lastTime * @access public - * @return bool|int + * @return bool */ - public function changeStatusRunning($cronID, $lastTime) + public function changeStatusRunning($cronID) { $data = new stdclass(); - $data->status = 'running'; + $data->status = 'running'; $data->lastTime = date(DT_DATETIME1); - $rows = $this->dao->update(TABLE_CRON)->data($data) - ->where('id')->eq($cronID) - ->andWhere('status')->ne('running') - ->andWhere('lastTime')->eq($lastTime) - ->exec(); - return dao::isError() ? false : $rows; + $this->dao->update(TABLE_CRON)->data($data)->where('id')->eq($cronID)->exec(); + return !dao::isError(); } /**