f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
207 stars 88 forks source link

Silent error in file caching #304

Open Sinthorion opened 4 years ago

Sinthorion commented 4 years ago

The built-in File-based cache engine checks cache entry existence by attempting a file read using the error silencing operator. This error from the file not existing will still be in PHP's error log (and populate error_get_last()).

This is especially a problem in page caching: F3 checks the error log and refuses to cache the page if there was an error. Since the existence cache before rendering the page always produces an error with no cache present and this error prevents the cache from ever being filled, this means the folder cache engine can never cache a page, as is, unless I'm missing something.

n0nag0n commented 4 years ago

We talked about this error silencing operator in the Base::read() method on the slack channel last week. No one seems to know how or why it got there because it also will fail if you try to read a config file and it can't find the config file.

Sinthorion commented 4 years ago

I imagine one reason to use the silencing operator rather than some explicit check like is_readable($file) is that there are rare situations in which a file reports as readable but something during actually reading fails. It's also possible for is_readable() to fail with an E_WARNING. The PHP docs aren't clear about what can make these functions error out. The silencing operator is thus a catch-all for all these special cases.

But at the very least, error_clear_last() should be called (possibly after checking error_get_last() first) every time after using the silencing operator.