zeldor.biz

Linux, programming and more

Copyright © 2025
Log in

APC – Alternative PHP Cache

June 21, 2011 by Igor Drobot Leave a Comment

A PHP-accelerator is a PHP extension designed to improve the performance of software applications written in the PHP language.

Most PHP accelerators work by caching the compiled p-code (portable code) of PHP-Scripts to avoid the overhead of reparsing and recompiling source code on each request made for example by a stupid bot.

APC is free, open source framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode compiler in shared memory. APC is quickly becoming the de-facto standard PHP caching mechanism as it will be included built-in to the core of PHP starting with PHP 6 <- Great news!

I wrote a long post about my current nginx setup and now I extend it by adding APC-Accelerator

My php5-fpm package comes from Dotdeb, its a good idea to use APC from them too;)
Debian way:

1
aptitude update &amp;&amp; aptitude install php5-apc

aptitude update &amp;&amp; aptitude install php5-apc

Fix Cache size for your Accelerator

1
2
3
4
5
cat /etc/php5/conf.d/apc.ini
; configuration for php apc module
extension=apc.so
; cache size
apc.shm_size=256

cat /etc/php5/conf.d/apc.ini ; configuration for php apc module extension=apc.so ; cache size apc.shm_size=256

Restart php5-fpm:

1
/etc/init.d/php5-fpm restart

/etc/init.d/php5-fpm restart

Now your cache is active! The package provide a apc.php to check the current status and memory allocation.

Cache usage:

General Information (click to resize):

Pos/NegativeHits:

And a little Hit-Bar for your cache – it looks great! – 99.6% of positive hits by a running duration of 9 hours and 25 minutes.

Thats not all, you will get detailed information too!

Let’s prove it!
I start a benchmark test before I enable APC:

1
ab -c5 -n3000 http://zeldor.biz/

ab -c5 -n3000 http://zeldor.biz/

Result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Server Software:        nginx
Server Hostname:        zeldor.biz
Server Port:            80
Document Path:          /
Document Length:        33586 bytes
Concurrency Level:      5
Time taken for tests:   9.331 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      101481000 bytes
HTML transferred:       100758000 bytes
Requests per second:    321.52 [#/sec] (mean)
Time per request:       15.551 [ms] (mean)
Time per request:       3.110 [ms] (mean, across all concurrent requests)
Transfer rate:          10621.03 [Kbytes/sec] received

Server Software: nginx Server Hostname: zeldor.biz Server Port: 80 Document Path: / Document Length: 33586 bytes Concurrency Level: 5 Time taken for tests: 9.331 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 101481000 bytes HTML transferred: 100758000 bytes Requests per second: 321.52 [#/sec] (mean) Time per request: 15.551 [ms] (mean) Time per request: 3.110 [ms] (mean, across all concurrent requests) Transfer rate: 10621.03 [Kbytes/sec] received

Now enable APC and run the test again – My result was positive!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Server Software:        nginx
Server Hostname:        zeldor.biz
Server Port:            80
Document Path:          /
Document Length:        33586 bytes
Concurrency Level:      5
Time taken for tests:   7.364 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      101481000 bytes
HTML transferred:       100758000 bytes
Requests per second:    407.40 [#/sec] (mean)
Time per request:       12.273 [ms] (mean)
Time per request:       2.455 [ms] (mean, across all concurrent requests)
Transfer rate:          13458.27 [Kbytes/sec] received

Server Software: nginx Server Hostname: zeldor.biz Server Port: 80 Document Path: / Document Length: 33586 bytes Concurrency Level: 5 Time taken for tests: 7.364 seconds Complete requests: 3000 Failed requests: 0 Write errors: 0 Total transferred: 101481000 bytes HTML transferred: 100758000 bytes Requests per second: 407.40 [#/sec] (mean) Time per request: 12.273 [ms] (mean) Time per request: 2.455 [ms] (mean, across all concurrent requests) Transfer rate: 13458.27 [Kbytes/sec] received

My conclusion will be short: Nginx+php5-fpm+APC =Awesome.

Filed Under: HTTP, Linux, Networking Tagged With: Accelerator, apc, Benchmark, Nginx, php5-fpm

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY DNS Fedora FTP Fun Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID rsync Samba security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *

Yeaaah Cookie! We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok