InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Site Performance tutorials

  • Chrome PageSpeed insights
  • Google custom search with lazy loading
  • Install and monitor memcache for php on Ubuntu
  • Internal vs external css
  • Javascript in header vs footer
  • PHP apc - setup and performance benchmarks
  • Php apc vs memcache
  • Using inline image for site performance
 
  • Home
  • > Tutorials
  • > Web Development
  • > Site Performance

PHP apc – setup and performance benchmarks on Ubuntu Linux

By admin | Last updated on Jan 11, 2016

APC (Alternative php cache) is opcode and object cache for php. It caches the php bytecode on first execution of a php script which increases the performance of php code on subsequent executions of same script. For the purpose of this article I’ll use it only for opcode cache. No data cache will be used.

APC installation

These are the steps to setup apc on Ubuntu Linux for Apache:

  1. First install the php-apc package using the following command:
    sudo apt-get install php-apc
  2. The package also installs apc.php.gz at /usr/share/doc/php-apc/apc.php.gz. Unzip and copy it to somewhere in your apache webserver document root. Here is a the command you can use:
    zcat /usr/share/doc/php-apc/apc.php.gz > /path/to/document/root/apc.php

    This script (apc.php) is pretty useful to show various apc stats. Edit the file and set appropriate user and password for web simple auth access control.

  3. Visit http://yoursite.com/apc.php to view apc stats and current configuration settings. Here are some screenshots from it showing general cache information and host status.
    apc-general-cache-infoapc-host-stats

APC configuration

The full list of apc configuration options at can be seen at php.net. Here are some options which you may want to look at for quick start:

  1. apc.stat: Default value is 1. This means that apc will check the php file modification time each time to see if file needs to be reloaded. Setting it to 0 may have slightly better performance but it will drawback of executing old php even if a php file is modified unless apache is restarted.
  2. apc.shm_size.  Size of the shared memory segment. You may want to increase it if you see cache is close to full in cache stats.
  3. apc.max_file_size. Default value is 1M. You can decrease it if you don’t have too much memory and want to cache only smaller files.

I think in most cases the default configuration values should be good enough. You can run apc for sometime with default values and see if something needs to be changed.

APC – benchmarks

Here are the details of the system used:

  1. WordPress 3.5.1 on Ubuntu Linux server 12.04.1 LTS on AWS EC2 micro instance
  2. php apc 3.1.7-1
  3. PHP Version 5.3.10
  4. Command used to measure performance
    ab -n 10 -c 1 https://infoheap.com/
    The output is recorded in 2nd run of the command.

Here is the outcome of 3 experiments I did:

  1. Experiment 1: No apc installed
    Time per request:       26.302 [ms] (mean)
  2. Experiment 2: apc with default apc configuration
    Time per request:       16.705 [ms] (mean)
  3. Experiment 3: apc with apc.stat:0
    Time per request:       16.662 [ms] (mean)

 Conclusion

There is approx 36% improvement when php apc is installed vs when it is not installed. Switching off apc.stat did not really result in any significant benefit. So its better to keep apc.stat to its default value.

Suggested posts:

  1. Php apc vs memcache
  2. How to use ssh port forwarding to surf a site from different location
  3. How to create facebook page username for vanity url
  4. PHP sort associative array using custom compare function
  5. Why and how to log Content-Type in apache access log
  6. Bash – variables in double quotes vs without quotes
  7. migrate multiple mysql databases using mysqldump on Linux
  8. How to migrate your site from one domain to another
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged PHP, Site Performance, Tutorials, Webmaster
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress