Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP APC Cache, does it work out of the box?

Tags:

php

caching

apc

So this is whats bothering me. I just installed APC cache and Im testing it. When using APC Admin interface, in apc.php file, I can see all the info about APC etc. When I go to System Cache Entries I can see that every script i invoke gets written there.

So does this means that APC Cache works out of the box? I can just install APC cache and it already speeds up my application by caching scripts? And if I want I can then cache variables to make it even faster?

Hope you get the question, its probably simple to someone with more experience with APC.

Its I know i can add some variables to cache, and then get them out and that will speed up my app. But is it true, that APC will speed up the app and cache scripts all by him self? And is there any good documentation where I could learn more about APC?

like image 670
otporan Avatar asked Oct 20 '12 21:10

otporan


People also ask

How does PHP cache work?

PHP by itself does not do caching. But there are opensource frameworks to let the programmer design their code to work this way. In other words, it lets the code check if the data has already been retrieved before it goes and fetches it again, which is a relatively slow process since it has to query the database.

How does PHP store data in cache?

The easiest is to serialize() the data and store it in your database. When you need to retrieve the database, query it from the database, unserialize() it, and use it as before. As second approach is to add memcache to your PHP installation and access your data via the memcache functions.

What is APC user cache?

APC or Alternative PHP Cache, is a free open-source opcode (operation code) caching plugin for PHP. With APC caching your PHP script executions can run more efficiently, by cutting down on dynamic PHP executions.


1 Answers

Yeah, APC "just works". Anyone running PHP in production without APC/(other opcodecache) is missing out on the easiest performance improvement they can readily achieve.

A few caveats though.

If you are in development, you can still run APC, however, you probably want to enable stat calls. This means that APC will check the last modified of your files.

apc.stat = [1|0]

So if you don't have stat calls enabled, and you change a file and APC has already cached it, then it won't observe your changes, and you will continue using the cached opcode.

As you have mentioned, APC isn't just for opcode caching, it is also useful for user space caching. You have your system cache and your user cache.

You can store things against your user cache by just performing something like:

apc_store("fooKey", "barValue");

like image 80
Layke Avatar answered Oct 12 '22 23:10

Layke