-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Improve check on loading cached file if the file not found #19773
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
Conversation
@@ -110,7 +110,7 @@ protected function getValue($key) | |||
{ | |||
$cacheFile = $this->getCacheFile($key); | |||
|
|||
if (@filemtime($cacheFile) > time()) { | |||
if (file_exists($cacheFile) && @filemtime($cacheFile) > time()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It may result in additional stat call.
- It becomes non-atomic operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, why do we want to avoid it at all costs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filemtime
assumes that file already exists - which is already wrong assumption. Then it solves situation with non-existing file by suppressing error - which is also wrong approach. PHP has dedicated function(s) to check whether the file exists - so why not to use it properly? It is not adding extra stat call since stat data are memory cached on first attempt. The currently implemented mechanism is also not 100% atomic anyway since there is microtime between @filemtime
and @fopen
and @flock
in the block (BTW would not file_get_contents()
be better?). Should you wish I can add extra suppress operator @file_exists($path)
even though I don't think it'd be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lubosdz because there's a time gap between file_exists
and filemtime
. file_get_contents()
with locking flags might be, indeed, better in terms of atomicity.
Why do you have these errors in logs? They're suppressed, they should not be reported by PHP. |
@rob006 It's the debugger setting, which overrides PHP environmental settings. I could configure debugger to ignore any error/warning/level, but I don't wanna do that, since I want to catch off all issues in development. |
Can you configure debugger to ignore only suppressed errors/warnings? This is default PHP behavior and the whole point of
This is not Laravel implementation, this is some random 3-party package. Suppressing errors here is a must. |
@rob006 As I wrote above - yes, I could configure dbg to silently ignore those errors. But that's not the point here - the motivation is to fix faulty implementation with faulty assumption. The decision is up to core developers - feel free to close issue or leave open for some time if there would be some related feedback .. whatever you do :-) |
What faulty assumption? It is expected that |
Yeah, your subjective view of what's faulty differs from my view. That's normal. Do whatever you do, I don't wanna waste my time arguing. |
Ah, all in all I understand now and since it was already discussed and agreed upon, I'm closing this PR. I'm afraid @lubosdz that you need to handle that logs on your side. |
This fixes annoying errors in debug mode when attempting to load from cache non-existing file (filecache only). Adding simple check whether the file exists fixes the issue.