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

Nicola Peluchetti picture Nicola Peluchetti · Oct 26, 2012 · Viewed 9.3k times · Source

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?

Answer

Nikolaos Dimopoulos picture Nikolaos Dimopoulos · Oct 26, 2012

You can try the extension_loaded function

$is_apc_installed = extension_loaded('apc');