当前位置:首页技术文章thinkphp 写入缓存失败调整方法

thinkphp 写入缓存失败调整方法

作者:11
更新时间:2019-04-15 07:38:56
阅读量:0

打开文件thinkphp/library/think/cache/driver/File.php

替换以下函数即可

	public function set($name, $value, $expire = null) {
		$this->writeTimes++;

		if (is_null($expire)) {
			$expire = $this->options['expire'];
		}

		$expire = $this->getExpireTime($expire);
		$filename = $this->getCacheKey($name);

		if ($this->tag && !is_file($filename)) {
			$first = true;
		}

		$data = $this->serialize($value);

		if ($this->options['data_compress'] && function_exists('gzcompress')) {
			//数据压缩
			$data = gzcompress($data, 3);
		}

		$data = "\n" . $data;

		//$result = file_put_contents($filename, $data);
		$result = @fopen($filename, "w");
		for ($i = 0; $i < 5; $i++) {
			if ($result) {
				break;
			}
			usleep(500000);
			$result = @fopen($filename, "w");
		}
		fputs($result, $data);

		if ($result) {
			isset($first) && $this->setTagItem($filename);
			clearstatcache();
			fclose($result);
			return true;
		} else {
			return false;
		}
	}

 

下一篇:没有了
阅读排行
0.040090s