You should use the JSR-223 scripting API. There is a PHP implementation that uses a Java/PHP bridge:
http://php-java-bridge.sourceforge.net/pjb/
Another is pure Java:
http://www.caucho.com/resin-3.0/quercus/
I have not used this myself. But Caucho's Quercus product uses it, so I would suspect it is mature enough to do whatever you need.
http://quercus.caucho.com/
Here are some other links that may help you:
https://scripting.dev.java.net/
http://jcp.org/en/jsr/detail?id=223