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.
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.
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
Anonymous
April 14, 2008
3 years 41 weeks
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.
voyageur
April 14, 2008
3 years 41 weeks
Try apc.shm_size = 64
I bet you will see in apc.php report that there is 64MB available with 1 segment.
Anonymous
July 9, 2008
3 years 28 weeks
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.
Anonymous
October 27, 2009
2 years 13 weeks
Wrong format for apc.ini.
There my be an issue with your syntax. I use the following settings:
extension=apc.so
apc.enabled=1
apc.ttl=7200
apc.user_ttl=7200
apc.shm_segments=3
apc.shm_size=256
Using quotes causes that value to not actually be changed. i.e.,
apc.shm_size="256"
forces APC to use the default value of 48MB. The same with shm_segments -- it will stick to the default of "1" if you use quotes.. so.. don't. :)
Jason Fisher
Anonymous
October 31, 2010
1 year 12 weeks
Need to use a size letter
If you look in Apache error log it tells you you need a size unit.
Try adding an M to tell it Megabytes
apc.shm_size="256M"
Regards,
James Rudd
Anonymous
July 30, 2011
25 weeks 6 days
hitting a weird problem over
hitting a weird problem over here. apc is compiled with mmpa, and when I open apc.php it reports:
(mmap memory, pthread mutex locking)
but further down, in the runtime settings it says:
so why isn't it using the 64M :-(