---
---
Indrek's JIT-PHP

This is another approach to the PHP language compiled script caching. I have written this piece by piece through the years. As there are already half a dozen products offering similar functionality the code has no real strategic or commercial value. But I figured it's just as bad leaving it rotting on my hard drive so I decided to clean it up and publish to Internet.

So this software is just provided for your information only. You might test it and see how it performs but I have no reason right now to start maintaining and perfecting it.

Download

The source code is available for download. As it stands there are no binary packages avilable. The current version is at 0.1 - jphp-0.1.tar.gz. Please read this document or the provided README.

Quality

The code is definitely not production quality. Although it has been debugged reasonably well (using valgrind and stresstesting) it does lack real world experience. As you read the license there are no warranties.

The bulk of code has been written using the C++ language. I also made heavy use of the C++ STL feature. The code still is not perfect as I had no time to refine it and did a few quick hacks. Also in the past I lacked many skills as a C++ developer so it can be primitive and have some questionable design issues.

Performance & Optimizations

JIT-PHP does several optimizations. It encodes the script and applies additional optimization to the bytecode. The files are stored on both the hard drive and optionally in IPC shared memory segment for extra quick access. Also JIT-PHP does its own bytecode execution and has extended the process for better speed.

So the performance of JIT-PHP should match that of other similar softwares. When it comes to simple filesystem based caching (not shared memory) it should be somewhat faster due to its binary approach.

One of the unique feature of JIT-PHP is that it extends the instruction set of PHP language and provides its own execution code (modified zend_execute.c from the Zend engine). The performance should be close to the Zend(tm) Optimizer product with a few exceptions.

There is one thing that is a bit slower - calling PHP defined functions. This could be optimized of course by resolving the symbols at load time.

The current source code has been tuned to the gcc 3.3. With a bit of hacking you should be able to get it to compile on older gcc. In my previous tests the gcc 2.95 generated code was around 5-10% faster than that of gcc 3.3.

On a more philosophical note the execution speed is not something extreamly important, especially in the business of web sites. Proper content management and caching features produce far better results.

Platforms & Architecture

The code was developed on a x86 Linux system (SuSE 8.0, 8.2). I don't see any inherent reason why it should not run on other x86 based UNIX systems. It is inherently tied to the gcc implementation. Notably it uses the gcc jump tables to speed up execution.

There is a binary hack in use (freplace.cc) that is architecture dependant. I developed code to implement it on the SUN sparc architecture but I have not tested the whole software there.

Also memory alignment would have to be tuned on more demanding systems (data.cc).

The freplace.cc may also come to problems with memory protection systems.

Compilation & Installation

You need to have the source distribution of PHP to compile jphp. I have tested compilation with php-4.3.1 and php-4.3.2. Edit the Makefile and change the PHPTREE variable pointing to the untared php source tree. If you are running a weird system you might need to do additional hacking - like changing the optimization flags for gcc.

Type make and hopefully you'll end up with libphpjit.so. Copy it to a safe directory and add the following line to your php.ini:

    zend_extension = "/path/to/libphpjit.so"

There are additional configuration directives available in the file CONFIGURATION. Please read it. That's about it.

Licensing issues

The code is currently distributed under the Q Public license (see the LICENSE.QPL). This disallows you to use this software for purely closed commercial purpose.

The reason is that not only does this software do translation and encoding of your scripts - this software also loads, binds, interpretes and executes your scripts.

Links to similar software
---
Copyright © 2001-2017 Indrek Mandre