15

I'm writing a wordpress plugin where the CSS is compiled dinamically and thus i've implemented various strategies to cache it. As of now the first choice for caching is APC if it's installed.

This is how i'm checking it

    $is_apc_installed = function_exists('apc_store')
        && function_exists('apc_fetch') && ini_get('apc.enabled');
    $sapi_type = php_sapi_name();
    if (substr($sapi_type, 0, 3) === 'cgi') {
        $is_apc_installed = false;
    }
            

but on some installs i still get that apc_fetch() always return false. What else should i check to be sure that APC is working correctly?

LuFFy
  • 8,799
  • 10
  • 41
  • 59
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192

2 Answers2

17

You can try the extension_loaded function

$is_apc_installed = extension_loaded('apc');
Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
5

There are also 2 other possibilities

$is_apc_installed = ini_get('apc.enabled') && extension_loaded('apc');

or simply with console

php -i | grep apc
LuFFy
  • 8,799
  • 10
  • 41
  • 59
Robert
  • 19,800
  • 5
  • 55
  • 85
  • thank you this is very helpful for AWS Elastic Beanstalk. Configured APC via the `.ebextensions` module but had no idea if it was actually running. – fIwJlxSzApHEZIl May 31 '18 at 19:57