Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

缓存文件读取异常 #6

Open
hongweipeng opened this issue Jun 9, 2020 · 4 comments
Open

缓存文件读取异常 #6

hongweipeng opened this issue Jun 9, 2020 · 4 comments

Comments

@hongweipeng
Copy link
Member

20200609230445

页面调起约 6~7 个ajax请求,PDOConnection 中有用到文件缓存。应该是文件缓存写入文件时 file_put_contents($filename, $data); 没加所导致的。

@yunwuxin
Copy link
Member

现在也收到了其他人的同样的错误反馈,但是他使用的是redis驱动,还在跟踪中

@hongweipeng
Copy link
Member Author

我使用倒是文件驱动,file_get_contents 会返回空字符串,我试着给 file_put_contents 添加 LOCK_EX 后问题还是存在。

@hjb0924
Copy link

hjb0924 commented Jul 28, 2021

这个问题是出现在并发的时候,缓存文件读写频繁没有加锁,导致读取数据异常,感谢隔壁某大神帮忙解决问题

@yi-shiyu
Copy link

做一个 小项目使用文件缓存验证token和续期频繁读写遇到了这个问题,解决如下,在driver 的file里面get方法的
$content = @file_get_contents($filename);改成
$content = false;
$file = @fopen($filename,'r+');
if ($file && flock($file,LOCK_EX)){
$content = '';
while ($s = fgets($file)){
$content.= $s;
}
flock($file,LOCK_UN);
fclose($file);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants