2

I am running a PHP application on azure and am experiencing some strange behaviour: This snippet runns in a Console command:

public function fire(Illuminate\Contracts\Cache\Repository $cache) {
    $cache->forever('someKey', 'someValue');

    var_dump($cache->get('someKey'));
}

The output is:

NULL

Accessing the value through wincache_ucache_get after executing the command also returns NULL (with prefix and without). Has anyone a clue on this?


P.S.: As per phpinfo() the wincache usercache is enabled: wincache.ucenabled On


After some more debugging i know some more facts:

In an isolated php file wincache_ucache_set and wincache_ucache_get work perfectly.

However, the call to wincache_ucache_set in Illuminate\Cache\WinCacheStore returns false.

marstato
  • 363
  • 2
  • 12

1 Answers1

2

As there is a setting wincache.enablecli in php runtime to control whether wincache is enabled in CLI mode.

By default it is set 0 so that the function wincache_ucache_set() cannot work in artisan commands.

You can refer to the guide on Azure official about Changing PHP_INI_SYSTEM configuration settings, to set the

wincache.enablecli=1

in additional php configuration settings.

Then the following code snippet should work well:

public function fire()
    {
        wincache_ucache_set('foo','goo',0);
        var_dump(wincache_ucache_get('foo')); 
    }

or like:

use Cache;
public function fire()
    {

        Cache::forever('someKey', 'someValue');
        var_dump(Cache::get('someKey'));

    }
Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks for your answer! But it is not working for me: i set `wincache.enablecli=1`, `phpinfo()` reports `wincache.enablecli On On`. Now `wincache_ucache_set` returns `true` in the artisan command; `wincache_ucache_get` in the CGI scripts does not return the correct value. Is it possible that there are separate stores for CGI and CLI? – marstato Feb 11 '16 at 11:21
  • 3
    It seems that `wincache` will create different `user cache` instances for different users. Here the artisan commands in cli and http requests in cgi are different users. And they can not share their user caches. Maybe we need to some other cache types. Like "`file,array`" which will leverage the same local files to cache values, or the "`redis`" which can share values to different users. – Gary Liu Feb 12 '16 at 03:10
  • 2
    I can confirm that @GaryLiu-MSFT is correct; WinCache creates a separate cache for processes executed by CLI vs. processes launched via fastcgi. Source: I'm the current owner of WinCache. – DropPhone Aug 06 '16 at 18:25