8

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?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
otporan
  • 1,345
  • 2
  • 12
  • 29
  • 1
    Yes, if you see the scripts it's caching it works. Probably it needs some [finetuning of the configuration file](http://www.php.net/manual/en/apc.configuration.php) though, but that's all. – fvu Oct 20 '12 at 21:28
  • 1
    Thanks, so by default APC caches every script and saves it into RAM. So that way they are accessed much faster then from the HDD. So I can see benefits of using APC cache by just installing it, without doing anything else? – otporan Oct 20 '12 at 21:35
  • 1
    The **main** advantage is not that you save loading from disk but the fact that the bytecode is stored - without cache the code is reinterpreted each time it is run, with cache that step is skipped. – fvu Oct 20 '12 at 21:37
  • 1
    Oooh yes I get that. Since PHP is interpreted language and not compiled, APC will save "bytecode" into RAM and then would not need to interpret script again, since it could get it in bytecode from RAM. AWESOME!! And this all works out of the box? I just cant believe I didnt use this before. Didnt know it was that powerful! – otporan Oct 20 '12 at 21:44
  • 1
    Yeah, the fact that it's that simple is called progress I think. I remember fighting with Turck's MMCache and its successors, the fact that APC "just works" was quite an improvement. And yes, the effects of a cache are astonishing isn't it? – fvu Oct 20 '12 at 21:47
  • 1
    To tell you the truth, this is the first time Im using cache with PHP. And im doing PHP for a year now, and PHP is the first language I ever used so Im still learning, in 2011 I didnt know what function or variable is :D Before I was always thinking cache is something complicated but APC is easy to use. Now I only need to find solutions how to cache Domain Objects in my MVC so I dont need to use database every time. And then learn all about APC and Memcache and Memcached he, he... :) Yeah I believe it was much complicated to use cache before. Thanks for clearing the way for the new guys! :D – otporan Oct 20 '12 at 22:04

1 Answers1

8

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");

Layke
  • 51,422
  • 11
  • 85
  • 111
  • 1
    Thanks, so system cache is this what i experienced, every script is saved into RAM automatically, and user cache would be if I save something in cache by using apc_store() and then get it out using apc_fetch()? Is this correct? Thanks again! – otporan Oct 20 '12 at 21:40