检查APC是否已安装并正常工作的正确方法是什么?

时间:2021-11-07 10:49:27

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.

我正在编写一个wordpress插件,其中CSS是以dinamically方式编译的,因此我已经实现了各种策略来缓存它。截至目前,缓存的第一选择是APC,如果已经安装的话。

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?

但在某些安装中我仍然得到apc_fetch()总是返回false。我还应该检查以确保APC正常工作?

2 个解决方案

#1


15  

You can try the extension_loaded function

您可以尝试使用extension_loaded函数

$is_apc_installed = extension_loaded('apc');

#2


2  

There are also 2 other possibilities

还有其他两种可能性

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

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

or simply with console

或者只是使用控制台

php -i | grep apc

php -i | grep apc

#1


15  

You can try the extension_loaded function

您可以尝试使用extension_loaded函数

$is_apc_installed = extension_loaded('apc');

#2


2  

There are also 2 other possibilities

还有其他两种可能性

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

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

or simply with console

或者只是使用控制台

php -i | grep apc

php -i | grep apc