Friday, 14 September 2012

The Deadly Duo – PHP & JAVA using the PHP/Java Bridge


The era of open source technologies has been characterised by the unprecedented and almost exponential rise of the technology called PHP. It has spawned multiple open source frameworks that form the basis of some of the most powerful software web applications available today. On the other end of the spectrum you have Java, the old warhorse that just refuses to give up. When providing PHP development services, and designing and developing an app, what happens when you combine these two dependable and powerful technologies? Your app will definitely inherit the advantages of PHP and Java. But, how do you accomplish this? Here’s how.

When PHP 4 came out, it featured support for adding an extension that would enable the use of Java. But, as the technology evolved there was a need for change. In PHP 5 and PHP 6, you need to install and configure the PHP/Java Bridge. Only then, can you use Java classes within a PHP script. Let’s first define what a PHP/Java Bridge is. It is a version of a streaming, XML-based network protocol that connects a native script engine, such as PHP or Python to a Java VM. Installation and configuration of the PHP/Java Bridge requires hands-on Java SE and PHP5 core knowledge. You can easily download the bridge as a zip file from the project’s page. The installation is Java platform dependent. 

For J2SE,

  • Get a J2SE 1.6 or higher version installed
  • Get PHP 5.1.4 or higher installed
  • Locate and extract the php-java-bridge_5.2.2_j2ee.zip file to a folder
  • Access this folder directory via the command prompt and type: …>java –classpathJavaBridge.warTestInstallation
  • In the bridge folder you downloaded, locate the ext folder containing 4 .jar files
  • Copy the JavaBridge.jar and php-script.jar files to the J2SE/Java SE ext directory

For J2EE,

  • Put the JavaBridge.war archive in the auto-deploy folder of your J2EE server
  • Change the name of the archive to the name you desire to christen your app with
  • Wait while the auto-deploy process creates a directory associated with this archive
  • Now, test the new app using this URL: http://localhost:8080/appName
  • Alter parameters if the J2EE server is running on a different host or is listening on a different port

The bridge comes with a collection of PHP classes that facilitate the addition of Java code into PHP scripts. Some of them are:

  • java – access java type with the given name
  • java_autoload – loads a set of Java libraries in the PHP script in use right now
  • java_cast – converts a Java object into a PHP value
  • java_is_null – checks for a null value
  • java_session – returns a session handle
  • java_values – evaluates the object and retrieves its content

For these functions to work, your app must contain the related PHP classes, the main among which is the Java.inc class. We are an offshore software development company and have implemented this technique for developing web apps using PHP and Java. We offer PHP development services including PHP MySQL development to clients across the globe. You can hire php mysql developer from our talented pool of developers who have honed their skills in PHP and Java development technologies. Get in touch with us for the best and the most cost-effective PHP development solutions.

4 comments:

  1. Great post indeed and thanks for all the information, it was very helpful i really like that you are providing information on PHP and MYSQL with basic JAVASCRIPT,being enrolled in http://www.wiziq.com/course/5871-php-mysql-with-basic-javascript-integrated-course i was looking for such information online to assist me on php and mysql and your information helped me a lot. Thanks.

    ReplyDelete
  2. talented pool of developers PHP Development who have honed their skills in PHP and Java development technologies.

    ReplyDelete
  3. I also need this, if someone already get php/java bridge to work with Drupal so that it can communicate with the java backend, please help to share how to do this. I try to follow the instruction on php/java bridge page, but it seems not clear enough to implement for the case of Drupal.

    ReplyDelete