I’ve been working on MySQL optimization for a while, and though there’s still more to done on that front, I’ve gotten to the point where the the cumulative query times make up less than half of the page generation time.
So I’m optimizing code when the solution is obvious (and I hope to rope Zach into giving the code a performance audit soon), but I’m also looking at optimizing how PHP works.
Once upon a time, most of us ran PHP as a CGI, and every time a request came in, the PHP interpreter would have to launch, read/compile/execute the script, then spit out the result and shutdown. Now (hopefully) everybody’s running PHP as an Apache module, so all the time spent launching the interpreter, allocating memory and other resources for it, and then shutting it down and cleaning up after it, is done just once for each thread of Apache.
It might not sound like much, but I had a chance to compare CGI vs. module performance recently and found that a fairly simple, but frequently accessed script running as a CGI completely swamped a server as a CGI (creating a load average over 20), but was hardly noticed when running as a module.
But even as a module, the PHP scripts still need to be interpreted and compiled before they can be executed. And because of the way PHP works, this is done every time the page/script is requested.
Java programmers, among others, criticize PHP for this, but that small inefficiency is part of what makes PHP so easy to use (and popular). And that ease of use means people are building some really interesting apps worth scaling.
Anyway, there’s a solution to eliminate that inefficiency in PHP: intermediate code caching.
By caching the executable code generated by the interpreter, then the using the cached copy instead of the source script for the next request, you can enjoy the benefits of PHP’s easy development and compiled code’s fast execution time. A number of projects all promise anywhere from double to 10X jump in performance.
- ionCube PHP Accelerator
This has the most recognizable “brand,” and some hosting providers even offer it, but it’s offered only in binary form and the license seems intentionally ambiguous (um, not free?).
- Turck MMCache for PHP
Has a good performance chart, and is GPL’d, but development appears to have ended in 2003.
- afterBURNERr*Cache
Yeah, I had to point to a page in the Wayback Machine, this project is dead.
- Zend Platform Performance Suite
A commercial suite that includes piles of goodies, if you pay.
- APC: Alternative PHP Cache
It’s under active development and includes Rasmus Lerdorf, the guy who created PHP, among the project leads. License: BSD-style (non-copyleft)
I haven’t actually tried any of these yet, but I’m looking for information and suggestions, and I’m likely to try APC, maybe even Zend soon. Just as soon as I make an app compelling enough (and large enough) to need it.
php, caching, acceleration, zend, apc, intermediate code cache, optimization, scaling, web applications
Posted May 31, 2007 by Casey Bisson
Categories: Technology. Tags: acceleration, apc, caching, intermediate code cache, optimization, php, scaling, web applications, zend.
5 Comments
Comments RSS
TrackBack Identifier URI
Leave a comment
User contributed tags for this post:
apc php acceleration (54) - module (34) - php compiled code (32) - Php intermediate code (32) - speedy php (26) - cache page script php (25) - cache code in php (19) - php intermediate page (18) - php cache comparison (14) - php compile time caching (13) - scaling (12) - php speedy (11) - apache cache optimization (10) - intermediate code (9) - zend intermediate code (7) - sex (6) - php apc leopard (6) - php intermediate (6) - www.sex.marrakech (6) - memcached vs eaccelerator (6) - comments (6) - sex marrakech (5) - mmcache php 5.16 (4) - PHP cache script (4) - www.pink.tv.com (4) - speedy cache (4) - php caching script (4) - eAccelerator vs memcached (4) - leopard apc php (4) - memcache vs apc (4) - php cache cgi (4) - php cache query (4) - php cgi cache (4) - ioncube leopard (4) - leopard php apc (3) - php apc statistics (3) - PHP Caching and Optimization (3) - php cgi apc (3) - F (3) - php optimizer (3) - marrakech sex (3) - apc cache cgi (3) - leopard php memcache (3) - intermediate code wikipedia (3) - php apc statistic (3) - php5 cache (3) - php compile cache (3) - Alternative PHP Cache cgi (3) - php optimize generation time (3) - php optimizer comparison (3) - doggy (3) - php cache off (3) - apc php cgi (3) - alternative php cache benefits (3) - apc versus phpa (3) - php caching (3) - php-cgi memcache (3) - php request performance (3) - LEOPARD php-cgi: not found (3) - install apc leopard server (2) - apc vs zend wordpress (2) - zend cache PLUGIN (2) - sex in Marrakech (2) - php speedy alternative (2) - php speedy security (2) - zend cache vs memcached (2) - zend memcache php (2) - zend cache memcached (2) - php cache optimization (2) - php memcache leopard (2) - sex marakech (2) - zend platform vs memcached (2) - PHP Accelerator work with zend 2 and php5 (2) - PHP5 caching (2) - php require vs include performance (2) - PHP caching includes (2) - php cache mysql (2) - www pink com marrakech (2) - memcache zend cache comparison (2) - php cache compare (2) - apc php leopard (2) - memcache vs Alternative PHP Cache (2) - zend platform vs apc (2) - php caching leopard (2) - zend optimizer leopard server (2) - php apc includes (2) - Alternative PHP Cache with php cgi (2) - php-cgi apc (2) - www pink tv com marrakech maroc (2) - zend cache vs memcache (2) - php accelerator leopard (2) - how php speedy works (2) - require once vs include once php (2) - turk mmcache vs memcached (2) - apc php accelerator (2) - leopard php cgi (2) - Zend Code Acceleration problem (2) - apc cache vs memcached (2) - mmcache vs xcache (2) - apc zend (2) - 89 com (2) - sex and (zend) (2) - php domdocument vs include performance (2) - leopard memcache php (2) - zend scalling (2) - php compile intermediate (2) - wordpress php acceleration (2) - ZendOptimizer vs eAccelerator (2) - php cgi vs module performance (2) - cache query php (2) - interpreted vs. compiled code php (2) - zend cache (2) - php speedy not caching (2) - zend sex.com (2) - php apc vs memcached (2) - memcache vs zend cache (2) - benefits php cache (2) - java memcached vs php memcached (2) - sexy arab mans (2) - memcache vs xcache (2) - php apc vs query (2) - how to make query speedy (2) - xcache apc (2) - Zend Platform Performance Suite (2) - zend cach memcache (2) - apc query (2) - mac osx 10 5 leopard ioncube (2) - php apc vs memcache (2) - include once vs require once php (2) - apc require once (2) - php caching off (2) - apc php-cgi (2) - memcache vs zend platform (2) - Zend Platform vs Apache (2) - code caching in php (2) - code caching (2) - leopard ioncube (2) - php memcache alternative (2) - PHP code for train stops (2) - php include once vs include (2) - zend platform comparison cache (2) - php cache code (2) - php code caching (2) - eaccelerator vs zend optimization suite (2) - php Memcache (2) - vedio camera caché sex marrakech (1) - xcache versus apc (1) - 1. APC 2. XCache 3. Memcache (1) - leopard php memcached (1) - caching google translated page script php (1) -
Back in the day, when the company I was working for was one of the early adopters of the Zend Optimizer, you sometimes got into situations where the cache would not recognize if you changed a source file included by the main file you were executing. Because that seriously got into the way of short development cycles, and introduced a number of “fake” bugs that vanished once you turned the cache off, we used to develop without the cache. That, on the other hand, changed the timing of each script, and we got more (or less) contention on the underlying MySQL DB.
I guess what I’m trying to say is a) don’t believe this’ll solve every problem and b) I’d be curious about how other solutions or more modern versions of the Zend stuff work out. Not curious enough to try them out, though, I’ve left PHP behind for the most part
This all sounds incredibly important and I truly wish I understood it…because I know I need to be worrying about all these things on my blog too….HELP!
Signed blogging damsel in distress in Marrakesh
[...] I’m still trying to squeeze more performance out of MySQL. And since small changes to a query can make a big [...]
Stumbled here by accident, and though it’s a year old now thought I’d clarify the ionCube PHPA license. It is and always has been free, but do note that it reached end of life some time ago and EAccelerator is probably the best choice these days although we do have a new performance product that has not been released yet.
Back in 2001 when I created the PHP Accelerator it was a massive shock to Zend. There was APC and a few other opensource caches, but they were all 30% or so slower than Zend Cache. I’d been using PHP for only a few days when I realised that it was quite slow and that there had to be a way to speed it up, so I started looking at caching. I didn’t know about the other caches at the time, although when I did I realised that they were clearly missing a trick as their performance was poor in comparison to Zend.
Following a frantic 3 weeks of development, PHPA was usable and the first cache to match or run faster than Zend Cache, with the crucial trick being to execute code directly from SHM.
After releasing the PHP Accelerator for others to benefit, Zeev Suraski got in touch asking what the intentions were; he was clearly worried, and concerned that their monopoly on the PHP market was being threatened. As a gesture of good will I made a promise not to release the source, so it remained closed source but free and maintained for several years, and adopted by countless sites globally from hobby sites to large enterprises such as Yahoo.
After steering the APC developers in the right direction to improve their cache, and with other developers taking an interest in PHP internals, more caches appeared over time and there are several choices. EAccelerator, a fork of the dead mmcache project, APC, and the promising newcomer XCache are all worthy. EAccelerator in particular benefits from some good code optimisation strategies, helping to boost performance further.
@Nick: Thanks for the details. APC has been working well for me here, but perhaps I should look around again.