PHP-File-Cache icon indicating copy to clipboard operation
PHP-File-Cache copied to clipboard

Cache rarely cannot be read resulting in read exception

Open Wruczek opened this issue 5 years ago • 3 comments

It seems like it happens randomly without any cause.

Wruczek avatar Jun 28 '19 00:06 Wruczek

Quickly scanning through the code - seems to be happening because you're not using file-locking and thus if you're accessing the file from more scripts running at the same time, you may get partial file because of the race-conditions. file_put_contents and file_get_contents are not atomic operations. This may be solved with LOCK_EX in the file_put_contents AND using flock around file_get_contents (or using flock/fopen instead of the file_get_contents altogether).

007hacky007 avatar Oct 08 '22 11:10 007hacky007

Thank you for your tip! Now that I think about it, it might be the case. I will try to fix the issue by locking the file.

Wruczek avatar Oct 08 '22 13:10 Wruczek

Still needs testing to make sure the issue is fixed

Wruczek avatar Oct 20 '22 02:10 Wruczek