There are a number of accelerator / compiler projects around, some of which are free. However, few of them work properly with PHP 5.1.3 (i.e. unreleased) yet.

I tried using APC a while back (the only "official" one as far as I know), but its behaviour is peculiar- it doesn't seem to do much and it crashes the CLI on exit (even if disabled at the time).

Anyway, apparently "eAccelerator" is the one to use.

I did some informal benchmarks here on Linux / Apache / PHP 5.1.3, here are some results:

A typical page generation time without eaccelerator - 80 milliseconds
With eaccelerator - 16 milliseconds.

This particular page doesn't do very much database access (probably only a couple of queries) but does use Smarty to generate the HTML.

Anyway, it's a good performance increase.

The process was repeated several times. Of course your mileage may vary.

My recommendations for anyone wanting to benchmark a PHP application page generation:

  • Use Apache to time the request time - it's not difficult
  • Do it on an otherwise idle machine - specifically, don't run the web browser on the same machine, otherwise you're timing your web browser's speed too. The web browser and server can fight for CPU causing detrimental performance.
  • Repeat the process a lot of times and discard outlying values.

Mark

    May be a little OT but apparently PHP6 is going to have the option of saving the optcodes to a file as a script is run for the first time, much like python does now. This itself is a huge performance boost.

      Well, if you're talking "official", then there's also Zend's Optimizer....

        I've read that optimizers aren't really necessary if you write decent code...???

        Yes No

        (As you can tell, I don't know the answer).

          How the PHP optimisers work, is that they pre-compile your scripts as byte-code (into memory or temporary files typically). This saves a lot of startup time parsing the PHP files.

          Normally, a well written application contains a lot of reused code, i.e. code shared between several scripts - sometimes a lot of code is included in a given script, then not used (because it's only there for consistency).

          The accelerator saves most of the startup time parsing your script and inside include(), require() statements etc.

          It typically does not optimise the runtime of your code much (if at all).

          However, this startup time can be a large proportion of the time taken, particularly for a simple page. Or something like Smarty which compiles its templates into .php files (which is very cunning, seeing as they can then be precompiled by the accelerator).

          Weedpacket: yes, Zend's optimiser is semi-official, but it isn't shipped with, or considered part of PHP, rather it's something which Zend ship (or sell?) independently under its own licence.

          Mark

            Zend's optimiser is semi-official, but it isn't shipped with, or considered part of PHP, rather it's something which Zend ship (or sell?) independently under its own licence.

            But, as I said.... this will be a part of php6. Maybe not the Zend optimizer exactly, but the option to save your scripts as optcode files.

              Nice info...didn't quite get it before now.

              Zend Optimizer, it seems, wouldn't be such a wise choice on a shared server would it (unless perhaps you were outputting temp files).

              I once tried installing this on my dev server and it just didn't want to happen...

                Zend Optimizer is not a opcode code cache. It is the Zend Encoder [now Zend Guard] loaders plus some "optimization" routines. What those optimizations are, I can't be sure, but I know for sure it is not an opcode cache. From a number of benchmarks I have seen, Zend Optimizer does not offer any kind of significant improvement over a plain PHP install; sometimes it even seems worse. It is so widely used though, because if you or someone on your server want to run Zend Encoded files, you have to run Zend Optimizer. Zend does not seem to provide a standalone loader option like IonCube and SourceGuardian do.

                Zend does have an opcode cache. It used to be free and was called Zend Accelerator [maybe there is some confusion that Zend Optimizer is Zen Accelerator; such is not so]. However, it is no longer free. You now only get it bundled as part of Zend Platform.

                I've been using APC in production for awhile with no problems that were not easily solved (I had one true problem, that really was a result of poor coding in an application). I'm running the latest version (3.0.10) on PHP 5.1.2 with no problems. It's performance is at least as good as eAccelerator's. I guess it [APC] had some problems early on, but it seems very stable and mature now. Yahoo! uses & supports the APC project, which I'm sure helped out quite a bit with getting it to where it is now.

                And as far as I have heard, the opcode cache that is going to be bundled with PHP 6 is going to be or be based on APC.

                Unfortunately, APC as well as most opcode caches are not compatible with Zend Optimizer, so if you need to run Zend Encoded files, then APC is pretty much out of the question. Well actually to be more precise, it is the other way around. Zen Optimizer purposely attempts to block 3rd party opcode caches .

                  Write a Reply...