Wruczek/PHP-File-Cache

Cache rarely cannot be read resulting in read exception

Wruczek opened this issue · 3 comments

It seems like it happens randomly without any cause.

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).

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.

Still needs testing to make sure the issue is fixed