How do I know if any PHP caching is enabled?
Asked Answered
L

4

27

I used to think caching was very hard to install so I've never done it... After reading about APC, it seems pretty easy to install. I always thought I would have to modify lots of PHP code inside my application to use it lol.

Anyways, I am wanting to install APC. I can use phpinfo() and notice it's not listed on the page, so it's not installed. Does this also show for the various other cache systems out there? I don't want to install APC if I have another caching system already installed since I'm not sure if it'll cause conflicts. Do hosts automatically install these for you?

What are the steps to check for to see if I have any sort of caching enabled?

Luker answered 9/12, 2010 at 0:5 Comment(0)
B
14

Any installed caching extensions will be listed in your phpinfo() file; They should be listed as one of the arguments in the "Configure Command" box (e.g. -enable-apc) and should have their own sections somewhere down the page.

Two of the most popular PHP caching modules are APC and Memcache.

Berard answered 9/12, 2010 at 0:19 Comment(1)
Thanks for the info. Looks like I don't have any installed.Luker
I
75

To check it programmatically:

if(extension_loaded('apc') && ini_get('apc.enabled'))
{
    echo "APC enabled!";
}

Note: As of version 5.5 PHP now has an Opcode cache/optimizer included (though disabled by default). If you still want to run APC there is the APCu extension as @alcohol mentions in a comment. If you are using that extension you would need to replace extension_loaded('apc') with extension_loaded('apcu'). Or you could verify it from the command line:

phpX.Y -i | grep apcu

Make sure though that you are using the same PHP binary that is used by your web server.

Interpretation answered 17/12, 2012 at 9:21 Comment(1)
There is also ext-apcu, specifically tailored because of the changes in PHP 5.5Jesusitajet
B
14

Any installed caching extensions will be listed in your phpinfo() file; They should be listed as one of the arguments in the "Configure Command" box (e.g. -enable-apc) and should have their own sections somewhere down the page.

Two of the most popular PHP caching modules are APC and Memcache.

Berard answered 9/12, 2010 at 0:19 Comment(1)
Thanks for the info. Looks like I don't have any installed.Luker
S
3

For those, who are using APCU (wich is replacement for APC)

Just run in command line:

php -r "var_dump(function_exists('apcu_enabled') && apcu_enabled());"
Suboceanic answered 14/5, 2021 at 9:25 Comment(0)
S
0

I think typically, most caching functionality for PHP will be in the form of extensions, and these should show up in a phpinfo() call (although you'll have to recognise them).

You will find some that are written in PHP, and can cache page loads, esp. when that content is generated from a database or from other web requests, etc but these will generally require knowledge of said library and would require you to modify your code.

It also depends on what type of caching you're looking for, as various extensions and programs perform different tasks. While APC caches your semi-compiled/interpreted code to increase performance, something such as memcache (also recommended) aims to reduce the load on any database functionality you may be using.

Personally, I would look to what functionality you require, and aim to install that - unless of course it already is.

Sheepwalk answered 9/12, 2010 at 0:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.