Clear APC Cache
In this tutorial I show you how to clear APC cache. Sometimes Magento shops are hosted on web servers with running APC for caching. I think this is not as usual as FPC caches, but now and then we discover shops that use this. Sadly it is not always possible to flush APC cache by backend, so you need access to server.
Clear APC Cache
An APC cache creates intermediate code. That is a compiled version of normal PHP script code and should run faster in computation. More about this topic can be found on official docu site. For me APC is unusual for Magento, because it already has an integrated compiler that can accelerate your shop. I have no compare values if an APC is faster, but for developers it is not very comfortable, because you can not flush it from Magento backend. You need to use web server procedures.
How to flush
The suggested method to flush an APC is with following three functions from PHP code:
1 2 3 | apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); |
On command line you may run the following:
1 | php -r "apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode');" |
APC configuration
APC is configured with php.ini on your web server. A config example may look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ... [APC] extension = apc.so apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 14M apc.optimization = 0 apc.num_files_hint = 512 apc.user_entries_hint = 1024 apc.ttl = 0 apc.user_ttl = 0 apc.gc_ttl = 600 apc.cache_by_default = 0 apc.slam_defense = 0 apc.use_request_time = 1 ;OR apc.mmap_file_mask = /dev/zero apc.file_update_protection = 2 apc.enable_cli = 0 apc.max_file_size = 2M ... |
Please read about full configuration in official documentation. APC makes only sense if it configured correctly. If you not sure what to do, please use Magento built in PHP compiler.
Conclusion
You can clear APC from php with just three functions. It is important to know, that every change in PHP script only takes effect after a cache flush. Working on a Magento shop under APC can be confusing, if you do not know about caching and if you do not know how to flush APC cache correctly.