What is the correct way to check if APC is installed and working?
Asked Answered
S

2

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?

Sharpe answered 26/10, 2012 at 13:56 Comment(0)
S
17

You can try the extension_loaded function

$is_apc_installed = extension_loaded('apc');
Ssw answered 26/10, 2012 at 14:0 Comment(0)
S
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
Spanish answered 28/6, 2017 at 15:55 Comment(1)
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.Pauiie

© 2022 - 2024 — McMap. All rights reserved.