Explore

Loading

Thursday, December 20, 2012

Using the PHP/Java Bridge to Combine PHP and Java in the Same App


As you probably know, PHP 4 supported an extension for combining PHP with Java, but to combine PHP with Java in PHP 5 or PHP 6 you should install the PHP/Java Bridge, which the website describes as:
"... an implementation of a streaming, XML-based network protocol, which can be used to connect a native script engine, for example PHP, Scheme or Python, with a Java virtual machine."
In this article you will learn how to install and configure the PHP/Java Bridge and how to use Java classes in PHP scripts in a demo application. To use the PHP/Java bridge, you should have knowledge of Java SE and the PHP5 core, as well as how they interact.

Using the PHP/Java Bridge

The current distribution of the PHP/Java Bridge is available for download as a .zip file from the project page. The installation process depends on which Java platform will be interacting with PHP through this bridge. For J2SE, installation is simple:
  1. Install J2SE 1.6 or above.
  2. Install PHP 5.1.4 or above.
  3. Extract the php-java-bridge_5.2.2_j2ee.zip to a folder.
  4. From the command prompt, navigate to this folder and type: …>java –classpath JavaBridge.war TestInstallation
  5. In the current folder, you should see an ext folder that contains four .jar files. Copy JavaBridge.jar and php-script.jar to your J2SE/Java SE ext directory ({JAVA_HOME}/jre/lib/ext).

No comments:

Post a Comment