Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Warning thrown once maintenance file deleted #3

Open
mattattui opened this issue Feb 13, 2015 · 7 comments
Open

Warning thrown once maintenance file deleted #3

mattattui opened this issue Feb 13, 2015 · 7 comments

Comments

@mattattui
Copy link

With the PHP-FPM sapi (possibly with others), the PHP stat cache persists at least long enough that the realpath test in https://github.com/atst/stack-backstage/blob/master/src/Atst/StackBackstage.php#L21 will return true after the file is removed/renamed, resulting in the subsequent file_get_contents() call throwing an error.

I'm not sure what the best solution is. One is to clearstatcache(true, $this->path) just before realpath - but even though it's only clearing one file's realpath stats, it might still have a performance penalty.

Happy to submit a pull request if this solution is acceptable.

@mattattui
Copy link
Author

Anyone there? :)

@davedevelopment
Copy link
Member

Sorry Matt, I looked at the time and didn't have a solution. Calling clearstatcache would have to be a last resort for me, perhaps we should do it inside the conditional? Make's it messy though.

@mattattui
Copy link
Author

Yeah it doesn’t strike me as particularly elegant either, though it’s not the whole stat cache, at least.

The only other way I can think of dealing with it is by telling users to delete the maintenance file using PHP (unlink() then clearstatcache()) rather than just removing the file from the command-line.

On 5 Mar 2015, at 15:02, Dave Marshall [email protected] wrote:

Sorry Matt, I looked at the time and didn't have a solution. Calling clearstatcache would have to be a last resort for me, perhaps we should do it inside the conditional? Make's it messy though.


Reply to this email directly or view it on GitHub #3 (comment).

@davedevelopment
Copy link
Member

That wouldn't clear the stat cache for all fpm workers though, only the one that happened to do the unlinking.

@mattattui
Copy link
Author

Well… poop. Short of restarting php-fpm, I’m out of ideas!

@davedevelopment
Copy link
Member

Let's go with the inelegant solution then!

$path = realpath($this->path);

if (false !== $path) {
    clearstatcache(true, $path);

    if (false !== realpath($path)) {
        return new Response(file_get_contents($path), 503);
    }
}

@mattattui
Copy link
Author

Works for me! And no additional load when out of maintenance is plenty elegant enough for me.

Thanks <3

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

No branches or pull requests

2 participants