Accelerating PHP with Java
I started looking in to ways to increase the performance of my PHP web applications and read an interesting discussion on the upcoming release of Drupal 7 and how this particular development group is looking int using using Java to accelerate the performance of PHP applications by pushing off slow PHP functions to Java. Why Java over a developing PHP extension? From the author’s comment:
(1) Integrating with the Zend engine in C is awkward, at best. It doesn’t even look like C. Bridging PHP’s loose types to C’s strict types is also frustrating. (Java has strict types, too, but conversion is more straightforward.) (2) Java has a superior array of storage, caching, and cluster libraries, especially for web systems. (3) Anything coded as a C extension for PHP binds itself closely with PHP. PHP/Java integration strategies are generally more abstract, providing reusable functionality that’s easy to interface with other Java systems and scripting languages. C has nothing like JSR-223.
That’s great but how do I implement this? There are currently a few different options available to bridge PHP and Java:
- PHP/Java Bridge - Provides a bridge between the PHP application and Java using an XML based protocol to a server running the Java bridge application. Requires a PHP library to be included in order to access Java classes & methods.
- Quercus - Implementation of PHP 5 running in Java. This solution can run on top of many popular Java Webservers (Tomcat, GlassFish, etc..) and offer access to Java methods via the JSR-223 direct script access. No includes required, you can just call functions as if they were provided natively by PHP.
- Project Zero -A development suite that provides tools to develop applications in Java and PHP. It’s aimed at developing new applications using the sMash environment rather than running existing PHP applications.
Out of the three I’m leaning towards using Quercus since it has the least overhead with direct access to methods and dose not require any includes. It also works with existing PHP applications and would provide the most straightforward way to replace PHP function with Java methods.