If I'm not mistaken you should compile PHP as a servlet...
I'm trying to do that right now so I can use PHP inside Cocoon2..
In php compilation, use ./configure --with-java --with servlet.
For this to work, your JAVA_HOME and CLASSPATH should be set..
Check PHP's source code under sapi/servlet/readme for more info