Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if any PHP caching is enabled?

Tags:

php

caching

apc

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?

like image 935
Joker Avatar asked Dec 09 '10 00:12

Joker


People also ask

Do PHP files get cached?

You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists() on a file that doesn't exist, it will return false until you create the file. If you create the file, it will return true even if you then delete the file.

How does PHP handle cache?

php // Cache the contents to a cache file $cached = fopen($cachefile, 'w'); fwrite($cached, ob_get_contents()); fclose($cached); ob_end_flush(); // Send the output to the browser ?> If a cached file named $cachefile isn't found on your server, this code will be executed and will create the cache file itself.


1 Answers

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.

like image 197
Andreas Bergström Avatar answered Sep 21 '22 08:09

Andreas Bergström