APC for PHP better performance:
APC is a op-code caching for PHP. Once PHP code is run, APC caches the complied PHP code so for next time, time for compiling PHP will be reduce and gives faster performance. APC caches files in memory so performance of PHP code improves significantly.
Make sure PHP is installed first . we need to install few pre-requist for PHP.
$ yum install php-pear php-devel httpd-devel pcre-devel gcc make $ pecl install apc
Open APC config file and make sure you have atlest following configuration:
Enable APC for php.
The number of seconds a cache entry is allowed to idle in a slot before APC dumps the cache.
Size of memory for apc ( 1024 M)
Enable apc stats.
Enable APC for command line php operations.
Allow 2 seconds after a file is created before it is cached. This will prevent premature PHP pages to get cached.
Maximum size of single file that apc can store.
Maximum number of files APC can store ( rotation).
Maximum number of users data entries that APC can store.
You can put your configuration infile but i prefer to have separate file like above for configuration. Values mentioned above are for demonstration purpose, different values for APC can be set which depends on number of PHP pages, size of memory in server, number of page hits e.t.c
Restart httpd server:
service httpd restart
APC installation comes withfile, which can be use to monitor APC performance. This file can be found inside APC package OR can be download from ( unzip and look for file).
Onceis downloaded copy it to your domain so that you can assess it.
Now from browser, you can go to http://domain.com/apc.php. I prefer to wait for a day to see the APC performance so we can have clear idea how well our configuration did.
Sample output of APC:
Here, we clearly see that APC is not performing very well as we have 44% misses. To optimize this we can reduce the memory and also we can increase max_file_size and also TTL time so that more can be cached in APC. Normally when missed rate is more than 10% , its better to reconfigure the settings of APC.
Well tuned APC will look like below: