Alternative PHP Cache APC
|
|
|
|
| Articles Reviews PHP | |
| Written by Phil Harrison | |
| Sunday, 15 October 2006 | |
|
{mos_sb_discuss:37}
Alternative PHP Cache, or APC, is a PHP opcode caching engine, now provided for free as part of the PECL/PEAR repository. APC originated with Daniel Cowgill and George Schlossnagle, and was released by Community Connect, Inc. After the release of PHP5, Yahoo! modified APC to support the new Zend Engine, and it has since become part of PECL. APC works by taking the compiled code from the PHP runtime engine and storing it in shared memory for later access. Each time a script is downloaded, APC checks for a version in shared memory first, before recompiling and executing the script that resides on disk. Because PHP doesn't need to recompile the script each time, it can greatly speed up the response time -- speed increases of over four times or greater can be obtained in some situations.
APC can be installed as either a dynamic shared object (DSO), or built into PHP statically. The folllowing section shows you how to install the DSO version, as it doesn't require you to recompile PHP, and provides the flexibility to add or remove the DSO at will. Installing APC First, grab a copy of the latest version of the APC source code from the PECL website: http://pecl.php.net/package/APC. Once you have a copy of the source code in tar/gzip format, extract the package and change directory into the newly created source folder: tar -xvzf APC-3.0.5.tgz cd APC-3.0.5 Next, run phpize in the source folder. Be sure to use the correct path to your installed copy of phpize that comes with PHP: /usr/local/bin/phpize When phpize is running, you should see output similar to the following: Configuring for: PHP Api Version: 20031224 Zend Module Api No: 20041030 Zend Extension Api No: 220040412 After phpize is finished, run the following configure script, again substituting the proper path to your php-config and apxs programs: ./configure \ --enable-apc \ --enable-apc-mmap \ --with-apxs=/usr/local/apache2/bin/apxs \ --with-php-config=/usr/local/bin/php-config Then, build the shared object: make After it is done building, install the DSO (as root): make install At this point, there should be a copy of apc.so in your PHP extensions folder. To complete the installation, add the following to the extensions section of your php.ini file, and then restart Apache: extension="apc.so" Configuring APC In most situations, the default configuration that APC uses should suffice, but if you want to tweak your caching to suit your needs or system, you can use the following directives in php.ini:
Removing APC If there comes a time that you no longer want APC after you've installed it, you can follow these simple steps to remove it from your PHP installation. First, search for and delete the extension="apc.so" line from your php.ini file. Alternatively, you can just comment it out: ;extension="apc.so" At this point, you can restart Apache, and APC will no longer be active in PHP. If you wanted to completely obliterate the DSO from your machine, you can delete the apc.so file from your PHP extensions directory once Apache has been restarted. Powered by jReviews |
|
| Last Updated ( Sunday, 08 July 2007 ) | |
| < Prev | Next > |
|---|










