Yii2: APC cache is being required by default

Created on 15 Dec 2018  Â·  7Comments  Â·  Source: yiisoft/yii2

What steps will reproduce the problem?

I have updated yii2 through composer from Yii v2.0.5 to v2.0.15.1.

What is the expected result?

I expected no major breaking issue, and my application to work as is

What do you get instead?

Invalid Configuration – yii\base\InvalidConfigException
ApcCache requires PHP apc extension to be loaded.

in C:\xampp71\htdocs\myapp\vendor\yiisoft\yii2\caching\ApcCache.php line 47
The offending code is:

public function init()
    {
        parent::init();
        $extension = $this->useApcu ? 'apcu' : 'apc';
        if (!extension_loaded($extension)) {
            throw new InvalidConfigException("ApcCache requires PHP $extension extension to be loaded.");
        }
    }

My web.php config file:

'cache' => [
      'class' => 'yii\caching\FileCache',
 ],

I have tried changing the config to below but the issue couldn't be resolved:

'cache' => [
      'class' => 'yii\caching\ApcCache',
      'useApcu' => true,
 ],

The only fix that worked is to explicitly change

public $useApcu = false;

in the ApcCache class to

public $useApcu = true;

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.15.1?
| PHP version | 7.1.1
| PHP Compiler | MSVC14 (Visual C++ 2015)
| Architecture | x86
| Apache Version | Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/7.1.1
| Operating system | Windows 7 Professional Edition Service Pack 1

need more info

Most helpful comment

I'd still search for any APC usage, UrlManager should just use which ever cache component you've set and not exclusively APC

My huge config file had another reference of ApcCache several lines down which I had included to do some tests. Stupid me.

This issue now stands closed.

All 7 comments

Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

_This is an automated comment, triggered by adding the label status:need more info._

I would do a search in my code to see if there's any references to Apc that I'm not aware off.
Maybe there's an old config file.

After keenly looking at the Stack Trace, turns out the issue emanates from the urlManager configuration... when the enablePrettyUrl property is set to true , for some reason the urlManager is trying to look into the APC cache.

So the safest workaround on my part now is to set cache property of urlManager to false, and leave the ApcCache core class the way it was.

I'd still search for any APC usage, UrlManager should just use which ever cache component you've set and not exclusively APC

Another thing I've noticed, any reference to Yii::$app->cache... defaults to ApcCache.

I don't have any other config files apart from the standard ones in the config folder.

I'd still search for any APC usage, UrlManager should just use which ever cache component you've set and not exclusively APC

My huge config file had another reference of ApcCache several lines down which I had included to do some tests. Stupid me.

This issue now stands closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobit picture sobit  Â·  3Comments

schmunk42 picture schmunk42  Â·  3Comments

SamMousa picture SamMousa  Â·  3Comments

MUTOgen picture MUTOgen  Â·  3Comments

indicalabs picture indicalabs  Â·  3Comments