[top-think/think]session使用file驱动 在并发情况下报错

2024-01-31 892 views
3

报错信息:Return value of think\session\driver\File::read() must be of the type string, bool returned public function read(string $sessID): string { $filename = $this->getFileName($sessID); if (is_file($filename) && filemtime($filename) >= time() - $this->config['expire']) { $content = $this->readFile($filename); if ($this->config['data_compress'] && function_exists('gzcompress')) { //启用数据压缩 $content = gzuncompress($content); } return $content; } return ''; } 报错原因:由于read方法指定了返回值类型 但是gzuncompress函数在解压出错时 返回false 导致read方法返回的值类型和指定类型不同 上传的图片一直挂掉 直接贴代码

回答

7

改进了 高并发场景还是慎用file类型吧