Skip to content

Commit

Permalink
bug #23091 [Cache] ApcuAdapter::isSupported() should return true when…
Browse files Browse the repository at this point in the history
… apc.enable_cli=Off (nicolas-grekas)

This PR was merged into the 3.2 branch.

Discussion
----------

[Cache] ApcuAdapter::isSupported() should return true when apc.enable_cli=Off

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

By being sensitive to apc.enable_cli, CLI cache warmup is broken when the setting is set to off because a PhpFilesAdapter will be warmed up by the CLI, whereas the Web mode will look at the FilesystemAdapter pools, which will be empty.

Commits
-------

aadf263 [Cache] APCu isSupported() should return true when apc.enable_cli=Off
  • Loading branch information
fabpot committed Jun 9, 2017
2 parents c297144 + aadf263 commit 40beab4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Expand Up @@ -21,7 +21,7 @@ class ApcuAdapter extends AbstractAdapter
{
public static function isSupported()
{
return function_exists('apcu_fetch') && ini_get('apc.enabled') && !('cli' === PHP_SAPI && !ini_get('apc.enable_cli'));
return function_exists('apcu_fetch') && ini_get('apc.enabled');
}

public function __construct($namespace = '', $defaultLifetime = 0, $version = null)
Expand Down Expand Up @@ -69,7 +69,7 @@ protected function doHave($id)
*/
protected function doClear($namespace)
{
return isset($namespace[0]) && class_exists('APCuIterator', false)
return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== PHP_SAPI || ini_get('apc.enable_cli'))
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
: apcu_clear_cache();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Expand Up @@ -26,7 +26,7 @@ class PhpFilesAdapter extends AbstractAdapter

public static function isSupported()
{
return function_exists('opcache_compile_file') && ini_get('opcache.enable');
return function_exists('opcache_invalidate') && ini_get('opcache.enable');
}

public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function doSave(array $values, $lifetime)
$ok = $this->write($file, '<?php return '.var_export($data, true).';') && $ok;

if ($allowCompile) {
@opcache_compile_file($file);
@opcache_invalidate($file, true);
}
}

Expand Down

0 comments on commit 40beab4

Please sign in to comment.