Section 14.7. Using APC (Advanced PHP Cache)


14.7. Using APC (Advanced PHP Cache)

One of the biggest performance problems with PHP code has been that requests take longer the more the code PHP parses. Fortunately, there is now a solution: opcode caches. An opcode cache works by caching the output from Zend's compiler in shared memory so subsequent requests do not have to reparse the same code again and again.

APC is a popular open-source cache for PHP written by George Schlossnagle and Daniel Cowgill, available through PECL:

 shell$ pear install apc 

To use APC, you need shared memory enabled in your operating system. You also need the following snippet added to your php.ini file:

 apc.enable = yes apc.shm_size = 4 

APC will not start up unless apc.enable is true. The apc.shm_size directive tells how many megabytes of memory APC reserves for caching scripts. APC will reparse code if the source file is updated.

Now restart your web server, and you're all set.

Try profiling some scripts using APD after you have APC running. The require/include subroutines should disappear completely from the top CPU consumers after a couple of requests.



    PHP 5 Power Programming
    PHP 5 Power Programming
    ISBN: 013147149X
    EAN: 2147483647
    Year: 2003
    Pages: 240

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net