PHP on TomEE with Quercus (Caucho)

Caucho wrote for Resin Quercus. This is mainly (from a user point of view) a servlet managing PHP in a java container.

I first thought it was linked to Resin but in fact it is pretty generic and can be used in almost all containers (with sometimes some few limitations).

So i tried with my prefered container: TomEE.

I wanted to start with a maven war project then discovered quercus was not available in maven reporitories (at least last versions – 4.x.y). The expected development process (if i understood it correctly) is to deploy the quercus war then add php files in the exploded war.

As a workaround i used this pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""


        quercus is available as a war so prepare the overlay manually
        Note: for real project install manually resin.jar
                <!-- download and extract -->
                <get src="${quercus.url}" dest="${quercus.war}" />
                <unzip src="${quercus.war}" dest="${work.dir}" />

                <!-- clean up a bit - API are in the container -->
                  <fileset dir="${work.dir}/WEB-INF/lib" includes="cdi*.jar"/>
                  <fileset dir="${work.dir}/WEB-INF/lib" includes="java*.jar"/>

      <!-- to test it quickly with mvn tomee:run -->


This simply downloads quercus war and explodes it in the maven directory which will be used to build the war (i deleted Java EE APIs too since it was useless in TomEE).
In a real life project you’ll want to install quercus war to do a real overlay (or better: install resin library and configure yourself the quercus servlet). Nothing complicated so i’ll not detail it here.

Once this is done you can add all php files you want in src/main/webapp and then deploy your war. PHP files will be interpreted (and can be compiled if a licence file is added in quercus servlet configuration – see quercus documentation for more detail).

So fine you can execute PHP but you’re in a Java container! Quercus manages it, there are some linked between PHP and Java. I’ll just speak about one (but look quercus doc, it is much better than it): jndi_lookup(string). This method lets you lookup anything in the container JNDI tree.

By default TomEE deploys some EJBs. One of them is the TomEE Deployer. Its JNDI global name is ‘java:global/openejb/openejb/Deployer’ (we often use the shortname openejb/DeployerBusinessRemote ;)). From a quercus webapp you can query this EJB easily:

    $deployer = jndi_lookup('java:global/openejb/openejb/Deployer');
    echo 'Unique File = '.$deployer->getUniqueFile();

For information you can lookup ‘java:app/BeanManager’ too and get access to CDI world very easily :).

Now the harder will be to keep the better of both Java (EE) and PHP worlds without bringing back the worse of them.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s