Speed up PHP with APC

Jan 16, 2014, by admin

APC stands for Alternative PHP Cache,The Alternative PHP Cache (APC) is a free and open PECL package that provides an opcode cache for PHP. It’s a fantastic extension which provide robust framework for caching and optimizing PHP intermediate code.The extension is widely used by Facebook. Facebook also made a great contribution in APC extension optimization.

Now you have a question what is an opcode cache? As PHP is an interpreted language, every time a page is loaded your PHP script must be converted to a language the machine can understand. This is known as operations code or opcode for short. By caching the opcode at regular intervals of time, you can gain a boost because your code is no longer being converted with every page load. This becomes more of a benefit when you have a high volume of traffic to your website.

What’s the difference between APC and other types of caching?

APC for PHP is one of the most widely used PHP opcode caching solutions in use today, and APC is planned to be included in the next release of PHP 6 by default as well. You can utilize APC on a VPS (Virtual Private Server) or a dedicated server that is running PHP as either DSO or FastCGI. You might want to read about choosing the best PHP handler for your specific needs, and also a more in-depth explanation on what DSO and FastCGI are.

Another common caching module is Memcached, and the main difference between this and APC is that Memcached is a distributed and more robust generic caching platform, while APC is specifc to PHP. APC is great for when you need local caching of objects for your PHP applications that are relatively small and frequently accessed.

How to install APC

As mentioned above, APC is a PECL package so can install it with ‘pecl’ like this:

pecl install apc

If you are using Ubuntu you can install it from the repository:

sudo apt-get install php-apc

Once apc extension get installed, restart your web server and you can check to see if it installed correctly by checking phpinfo() as APC will now have it’s own section. The extension works well with all PHP versions up to PHP 5.4.