Skip to content
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

[Cache] Apcu adapter in CLI #36399

Closed
ossinkine opened this issue Apr 9, 2020 · 6 comments
Closed

[Cache] Apcu adapter in CLI #36399

ossinkine opened this issue Apr 9, 2020 · 6 comments
Labels

Comments

@ossinkine
Copy link
Contributor

Description

APCu cache adapter works when apc.enabled is on, however, in CLI mode with the apc.enable_cli turned off, the adapter generates a lot of messages like Failed to save key.
For the system cache, this was fixed in #23390 by installing NullLogger in the adapter.
However, the problem persists for example in this configuration:

framework:
    cache:
        pools:
            cache.default:
                adapters:
                    - cache.adapter.apcu
                    - cache.adapter.redis

I suggest checking the apc.enable_cli option in each method, and do nothing in CLI mode, don't try to call acpu functions.
Something like this:

protected function doFetch(array $ids)
{
    if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
        return [];
    }

    ...
}

If this is a good solution, I will create a PR. If not, what decision do you think would be good?

@nicolas-grekas
Copy link
Member

This would add runtime overhead for a piece of code that can be found in critical code paths.
Any other idea?

@ossinkine
Copy link
Contributor Author

If we determine can the adapter work in this environment or not in init method, we will only check a variable in each method and this is the smallest runtime overhead.

class ApcuTrait
{
    /**
     * @var bool
     */
    private $doNothing;

    private function init(string $namespace, int $defaultLifetime, ?string $version)
    {
        $this->doNothing = 'cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN);

        ...
    }

    protected function doFetch(array $ids)
    {
        if ($this->doNothing) {
            return [];
        }

        ...
    }
}

@Nyholm
Copy link
Member

Nyholm commented Apr 13, 2020

But, isn't this warning a good thing? If Im trying to use the Apcu cache when APC is disabled, I should get a warning.

If we mute the warnings then I might believe the cache is working.

@ossinkine
Copy link
Contributor Author

@Nyholm Actually APC is enabled for FPM but disabled for CLI which is a common behavior, not an exceptional case. So if I want to warm up the cache in CLI I expect Redis adapter warms it up but APC just be skipped and will work only for in FPM.

@Nyholm
Copy link
Member

Nyholm commented Apr 21, 2020

Actually APC is enabled for FPM but disabled for CLI which is a common behavior, not an exceptional case.

Yes. I know. I understand that.

So if I want to warm up the cache in CLI I expect Redis adapter warms it up but APC just be skipped

From your point of view, I understand that it would make sense not to have a warning.

But technically speaking; You are telling both RedisAdapter and ApcuAdapter to warmup. Since ApcuAdapter cannot warm up on your (normal) system, it has to log a warning. Same thing if your Redis server was unavailable you would expect a warning from the RedisAdapter.

The workaround is to tell only Redis adapter to warmup or to ignore the warning.

@nicolas-grekas
Copy link
Member

Closing as duplicate of #34962, for which I opened PR #36555, please give it a try.

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

No branches or pull requests

4 participants