|
Server : Apache System : Linux iZ6xhqomji47p1Z 5.10.134-15.al8.x86_64 #1 SMP Thu Jul 20 00:44:04 CST 2023 x86_64 User : www ( 1000) PHP Version : 8.1.30 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/fsjlkj.cn/vendor/alipay/lotusphp_runtime/ |
<?php
class LtStoreFile implements LtStore
{
public $storeDir;
public $prefix = 'LtStore';
public $useSerialize = false;
static public $defaultStoreDir = "/tmp/LtStoreFile/";
public function init()
{
/**
* 目录不存在和是否可写在调用add是测试
* @todo detect dir is exists and writable
*/
if (null == $this->storeDir)
{
$this->storeDir = self::$defaultStoreDir;
}
$this->storeDir = str_replace('\\', '/', $this->storeDir);
$this->storeDir = rtrim($this->storeDir, '\\/') . '/';
}
/**
* 当key存在时:
* 如果没有过期, 不更新值, 返回 false
* 如果已经过期, 更新值, 返回 true
*
* @return bool
*/
public function add($key, $value)
{
$file = $this->getFilePath($key);
$cachePath = pathinfo($file, PATHINFO_DIRNAME);
if (!is_dir($cachePath))
{
if (!@mkdir($cachePath, 0777, true))
{
trigger_error("Can not create $cachePath");
}
}
if (is_file($file))
{
return false;
}
if ($this->useSerialize)
{
$value = serialize($value);
}
$length = file_put_contents($file, '<?php exit;?>' . $value);
return $length > 0 ? true : false;
}
/**
* 删除不存在的key返回false
*
* @return bool
*/
public function del($key)
{
$file = $this->getFilePath($key);
if (!is_file($file))
{
return false;
}
else
{
return @unlink($file);
}
}
/**
* 取不存在的key返回false
* 已经过期返回false
*
* @return 成功返回数据,失败返回false
*/
public function get($key)
{
$file = $this->getFilePath($key);
if (!is_file($file))
{
return false;
}
$str = file_get_contents($file);
$value = substr($str, 13);
if ($this->useSerialize)
{
$value = unserialize($value);
}
return $value;
}
/**
* key不存在 返回false
* 不管有没有过期,都更新数据
*
* @return bool
*/
public function update($key, $value)
{
$file = $this->getFilePath($key);
if (!is_file($file))
{
return false;
}
else
{
if ($this->useSerialize)
{
$value = serialize($value);
}
$length = file_put_contents($file, '<?php exit;?>' . $value);
return $length > 0 ? true : false;
}
}
public function getFilePath($key)
{
$token = md5($key);
return $this->storeDir .
$this->prefix . '/' .
substr($token, 0, 2) .'/' .
substr($token, 2, 2) . '/' .
$token . '.php';
}
}