Search code examples
javaphpphp-5.2

What's the recommended way of running Java from PHP 5.2?


I want to call Java from PHP 5.2, running either on a webserver or from a command line script.

From PHP 4, this seems to be simple, and just involves installing the PECL Java extension.

Example code from the PHP 4 extension:

<?php
  // get instance of Java class java.lang.System in PHP
  $system = new Java('java.lang.System');

  // demonstrate property access
  echo 'Java version=' . $system->getProperty('java.version') . '<br />';
?>

However, this extension doesn't exist on PHP 5.

What is the closest alternative for PHP 5?

edit:

Really I'm looking for an interface similar to either a C PHP extension or to that provided by the PHP 4 Java extension. The Java program is fairly small and only needs to retain a small amount of state between calls and doesn't need to run asynchronously. The PHP script would only be running a small number of instances simultaneously.

This would also need to be deployed to multiple machines (running Ubuntu 9.x and Debian Lenny), so it should be simple to install.


Solution

  • This project seems to be a good bet: http://php-java-bridge.sourceforge.net/pjb/