FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator PHP separator APC Cache Optimization & Monitoring Using Web Interface

Topics

On this page

APC – Web-based User Interface

APC Cache Configuration

APC & WordPress + WP3 Total Cache

More:

APC Cache Optimization & Monitoring Using Web Interface

While we installed PHP with other things, we also installed a php-apc package.

APC is one of the most popular caching mechanism for PHP’s op-code caching. Once activated, it starts caching PHP codes automatically. It also works nicely with W3 Total Cache plugin for storing Object & MySQL caches.

APC – Web-based User Interface

Its always better to check if APC is working correctly. Thankfully, APC comes with file apc.php, which provides a simple web-based interface. Just copy it to your site’s web-root folder:


			cp /usr/share/doc/php-apc/apc.php /var/www/example.com/htdocs
		

Then open http://example.com/apc.php in browser.

In case you want to use admin-side of apc.php, you will need to change default password to something else.

Just open apc.php file and edit following line:


			defaults('ADMIN_PASSWORD','password');          // Admin Password - CHANGE THIS TO ENABLE!!!
		

You can change a few more defaults to customize web-based UI as per your needs.

APC Cache Configuration

You can tweak APC’s parameter by editing vim /etc/php5/conf.d/20-apc.ini (if you have installed PHP this way). In other cases, you can simply add following values to your php.ini

If apc.php is showing miss-rate above 10%, the chances are high that you need to change value of some APC configuration option.

apc-poor-performance

There are many APC configuration options, but I recommend making changes to the following:

Total RAM storage allocated for APC (default is 32 MB)


			apc.shm_size=1024M
		

Maximum size of a single file APC can store (default is 1MB)


			apc.max_file_size=10M
		

Number of op-code “files” APC can store (default is 1000)


			apc.num_files_hint=20000
		

Number of data entries APC can store (default is 4096)


			apc.user_entries_hint=20000
		

Once you are done with tweaking, you need to restart PHP. Command: service php5-fpm restart

APC & WordPress + WP3 Total Cache

If you are using W3 Total Cache plugin, then you must make use of APC for Database Cache and Object Cache. 

Check following screenshot:

W3-Total-Cache-APC-1

Note: W3 Total cache will offer APC storage option for Page Cache and Minify Cache also. Do NOT use it. “Disk enhanced” is better for Page Cache & Minify Cache.

There are many caching engines available for PHP but I like APC for its simplicity. Also APC will be official caching mechanism for PHP 6 (someday…)

More:

PHP-FPM: Socket vs TCP/IP and sysctl tweaking

PREVIOUS

Checking if PHP/WordPress can send mails

NEXT


Comments

  1. Tharindu Avatar

    Tharindu

    January 25, 2013

    Is it ok to enable page cache on w3tc if I have Nginx fastcgi cache enabled?

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 25, 2013

      There is no reason to enable both. Depending on nginx config either fastcgi or w3tc cache will be used. Not both.

  2. Pascale Beier Avatar

    Pascale Beier

    April 9, 2013

    Hey there,

    Up to now, the following is wrong:

    apc.shm_size=1024

    The apc.shm_size parameter has to be extended with a size unit, e.g. M or G:

    apc.shm_size=1024M

    or

    apc.shm_size=1G

    Thanks!

    1. Rahul Bansal Avatar

      Rahul Bansal

      April 9, 2013

      @Pascale

      Thanks for pointing it out. I will update it now. 🙂

      What I used was old-syntax. Its not wrong. It still works but generates warning.

  3. Fox Jones Avatar

    Fox Jones

    April 27, 2013

    In your final note you mention not to use Opcode APC for Page cache. But when I use “Page cache: Disk Enhanced”, my SSL sites break, and the style sheets aren’t loaded. APC option seems to be working, can you elaborate on why I shouldn’t be using it, or how I might solve the SSL problem with Disk Enhanced? Thanks for the excellent tutorials.

    1. Rahul Bansal Avatar

      Rahul Bansal

      September 30, 2013

      “Page cache: Disk Enhanced” is better because through APC-based cache, every page request will require a PHP call.

  4. Fox Jones Avatar

    Fox Jones

    April 27, 2013

    i’m sorry, that was browser cache that i was having problems with, and it seems o be resolved. you can delete my comments here. thanks.

  5. Bernhard Avatar

    Bernhard

    September 30, 2013

    Are you sure about values for apc.shm_size and espacially apc.max_file_size. Most webservers for small blogs don’t have so much RAM, that they can reserve 1G only for APC. Like my V-Server only has 1G running a multisite installation. I have only 96M fpr APC and even the caching plugin (Cachify) stores it’s values into APC, my cache is only 50% filled. Even though giving APC lots of RAM lowers the RAM usage of the Apache processes, I would save enough RAM for other processes like Apache and MySQL-

    I also wouldn’t recommend to set the max_file_size to such a high value (unless you really have 1G for APC). The largest file in the WordPress core ist only like 180K, so even the default value of 1M is more than enough.

    1. Rahul Bansal Avatar

      Rahul Bansal

      September 30, 2013

      In above tutorial apc.max_file_size is 10M not 1G.

      Most of our server and our client servers have minimum 32GB RAM. Of course, these configuration should be modified based on individual needs.

      In our case, we used to host wordpress, activecollab and many other apps. APC was used for opcode-caching as well as user-data cache. I think apc.max_file_size limit applies for user-cache data as well.

      By the way, we have now moved to PHP 5.5’s builtin zend opcache – http://rtcamp.com/wordpress-nginx/tutorials/php/zend-opcache/ and for data-store we are using memcache – http://rtcamp.com/wordpress-nginx/tutorials/php/memcache/

  6. yatin Avatar

    yatin

    December 3, 2013

    Hi Guys,

    I have centos server and php 5.4.22. I am facing some problem with the file cache info. while User Cache Information is working perfectly. as soon as I installed the apc and updated the settings, I got 100% green bar and 0% misses. Is this correct? below is the setting that I have used so far. Please help me to correct it so that file caches also start working.

    apc.enabled=1
    apc.shm_segments=1
    apc.optimization=0
    apc.canonicalize=1
    apc.serializer=DEFAULT
    apc.shm_size=64M
    apc.shm_strings_buffer=3M
    apc.ttl=0
    apc.user_ttl=7200
    apc.num_files_hint=1024
    apc.mmap_file_mask
    apc.mmap_file_hint=1024
    apc.mmap_file_mask=/tmp/XXXXXX
    apc.enable_cli=0
    apc.max_file_size=3M
    apc.cache_by_default=0
    apc.rfc1867_name=APC_UPLOAD_PROGRESS
    apc.rfc1867_freq=0
    apc.rfc1867_ttl=3600
    apc.lazy_classes=0
    apc.lazy_functions=0

  7. Rahul Bansal Avatar

    Rahul Bansal

    December 5, 2013

    I am no longer using APC. We switched to zend-opcache starting from PHP 5.5 – http://rtcamp.com/tutorials/php/zend-opcache/

    However, it’s possible to have 100% hits if nothing is getting modified on your server. Like a single-user blog using 3rd party commenting system.

    You can inspect what is cached in APC using web-viewer. There are two big buttons with text “System Cache Entries” and “User Cache Entries” for file-cache and user-cache. respectively.

    You can also comment out your custom APC config and switch back to default APC config. It might make a difference as well.

  8. Mahesh Avatar

    Mahesh

    January 31, 2014

    I am new to using APC. I have set apc.shm_size as 64M. I’m confused what could be the right value for apc.ttl value for a websies which gets hardly 200 visitors per day?

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 3, 2014

      I think you can leave it default. Size and TTL are not dependent on each other. Size controls how “much” you can cache and TTL controls how “long” you can cache!

  9. Dan Avatar

    Dan

    February 20, 2014

    Hi,
    where to download the apc.php web interface? The php5-apc package of Debian does not have anything but the changelog in /usr/share/doc/php5-apc/.

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 22, 2014

      Use find command to search.

      We have stopped using APC. We now use zendcache – https://rtcamp.com/tutorials/php/zend-opcache/ and memcache – https://rtcamp.com/tutorials/php/memcache/

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

LinkedIn

This field is for validation purposes and should be left unchanged.

Email*

SIGN ME UP

Δ


© rtCamp, since 2009. All rights reserved.

Powered by