您所在的位置:首页 / 知识分享

think\cache\Driver::unserialize() 本地运行一直报这个错误

2020.08.24

4995

wng_png

version 6.0.0RC3
服务器:window10 mysql8.0.12 php PHP 7.3.4
file:vendor\topthink\think-cache\src\cache\Driver.php
line:242
错误原因:Argument 1 passed to think\cache\Driver::unserialize() must be of the type string, bool given, called in vendor\topthink\think-cache\src\cache\driver\File.php on line 126

研究了一下原因:

因为vendor\topthink\think-cache\src\cache\driver\File.php 第98行 public function get()方法中第108行:$content = file_get_contents($filename)读取到缓存文件的内容为空(可能是由于服务器IO性能引起的文件的共享冲突导致的,也就是同时打开同一个文件)时,第120行:$content = substr($content, 32); substr函数返回了boolean false,导致vendor\topthink\think-cache\src\cache\Driver.php 243行:protected function unserialize(string $data) 方法出错,因为该方法的参数只接受string类型。临时解决办法就是循环读取缓存文件,一直读取到内容为止。即把 $content = file_get_contents($filename)改成:
while(strlen($content = file_get_contents($filename) ) == 0 ){
}
一起等待官方发布解决办法吧。

相关新闻

百度蜘蛛

2015.11.05

2885

supervisor程序监控配置,参数及中文详解

2020.12.26

1364

supervisor 程序监控