Quercus: Bring Java's Power to Your PHP Development (and Vice Versa)

Imagine the possibilities when a PHP developer can continue using the language's templating capabilities while leveraging Hibernate's object-relational features. Thanks to an open source project named Quercus, PHP and Java developers alike can mix and match the respective capabilities of both languages.

Quercus is a Java-based implementation of the PHP language, which allows PHP developers to continue using the familiar PHP syntax of the native C-based version just as they always have while plugging into any of the hundreds of Java-based enterprise technologies such as Hibernate and Spring. This approach (part of the movement that software architect Neal Ford famously defined as "polyglot programming") opens up a whole new world of opportunities for developers seeking to squeeze every last ounce of performance and capability from their application platforms.

In this tutorial I'll show you how to install and configure Quercus, and demonstrate how easy even a Java neophyte such as myself can begin using PHP and Java in a seamless fashion. As Ford declared in 2006, the "time of writing an application in a single general purpose language is over."

Installing Quercus

Quercus is bundled as part of the powerful Resin application server, meaning you'll actually need to install Resin in order to get started using Quercus. Resin requires JDK version 1.6, so be sure to check whether your Java environment meets this requirement before proceeding. Then, head over to the Resin download page to retrieve the latest version of the software.

Presuming you're running a Unix-based distribution, installation is as easy as running the familiar configure - make - make install sequence. After installation, you'll need to start the Resin application server by issuing the following command from within the Resin directory:

%>java -jar lib/resin.jar start Resin/4.0.9 launching watchdog at 127.0.0.1:6600 Resin/4.0.9 started -server '' for watchdog at 127.0.0.1:6600

If when attempting to start Resin you receive an error regarding the need to have a "compiled JNI" (as I did on Ubuntu 9.10), see this useful blog post.

When the server has started, open a browser and navigate to http://127.0.0.1:8080 . You should be greeted with the Resin default home page and links to the documentation and administration interface.

Executing a PHP File

Related Articles 10 Experimental PHP Projects Pushing the Envelope

If Resin started properly, you are ready to begin using Quercus. Test it out by navigating to your Resin installation directory's webapps/ROOT directory and creating a file named phpinfo.php . In it, add the following code:

<?php phpinfo(); ?>

Call the file within the browser ( http://localhost:8080/test.php ) and you'll see Quercus' own version of the output returned from the phpinfo() function.

Page 1 of 2