skip to content

Tune APC to Improve PHP Performance

Adjust the parameters

Having installed APC for PHP does not automatically improve the performance. You have to adjust the parameters. At the very least, change these values:

apc.ttl="7200"
apc.user_ttl="7200"
apc.shm_segments="3"
apc.shm_size="90"

Setting apc.ttl and apc.user_ttl to none-zero can ensure that the cached php code gets refreshed at the given number of seconds without filling up the memory with stale entries.

The number assigned to apc.shm_size is the size of each shared memory segment in MB. To find the Linux kernel's maximum shared memory size, do

# cat /proc/sys/kernel/shmmax

If you already set the apc.shm_size to the maximum allowed size, then raising the value of apc.shm_segments would be the next thing to do.

Of course you can always raise the maximum size of a shared memory segment, using sysctl. Do this only when you know what you are doing. Run "man sysctl" for more information.

MMAP v.s. System V IPC

I did an experiment on APC version 3.0.14, on a system using mmap for shared memory. It seems that APC simply ignores the value in apc.shm_segments and go with the setting in apc.shm_size, and it accepts values larger than the maximum allowed size for each segment. In other words, it takes apc.shm_segments as 1, and accepts whatever value in apc.shm_size. This does conflict with the APC documentation. I saw others have filed similar bug for APC. I suggest you test this yourself and see if  things have changed since.

apc.php

To see how your APC is doing, locate the apc.php that comes with the extension, copy it to the document root, and access it from a browser. Please remember to remove this file from public access for security.

Reference: http://www.php.net/apc

Comments

Confirm that apc.shm_segments is working

Can anyone confirm that apc.shm_segments is indeed working?

I am using APC 3.0.16 on Debian Etch 64-bit installations with Apache/2.2.3 and PHP/5.2.0-8+etch10.

I have apc.shm_segments = 2 and apc.shm_size = 32, but apc.php only reports 32 megs available in 1 segment with 100% usage.

Try apc.shm_size = 64

I bet you will see in apc.php report that there is 64MB available with 1 segment.

djonline:

Why APC width php+fastcgi use different SHM for each php process ? Is SHM not one for All processes on the server ? Each time i refresh apc.php i see different uptime and different user data cache.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.
Powered by Drupal.