* merge ztSessionHandler.

This commit is contained in:
wangyidong
2022-11-10 15:47:05 +08:00
parent e8f50c14c6
commit 6eae8345f7
4 changed files with 27 additions and 22 deletions
+13
View File
@@ -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();
}
+7 -6
View File
@@ -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;
}
+2 -6
View File
@@ -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);
}
}
+5 -10
View File
@@ -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();
}
/**