What is Php-java-bridge?
PHP calls Java method has RPC, also has php-java-bridge.
PHP calls the Java platform packaged in the jar package of class and method, generally floating easily recommended practice is to use Php-java-bridge do bridge.
Which is better, we'll discuss it later.
Php-java-bridge implementation principle.
First open a listening port in Java, when PHP calls Java, the corresponding method calls forwarded to the Java specified port, executed by Java and then return the results to PHP.
This mode is a more typical proxy mode, where PHP becomes a proxy forwarder that forwards Java class calls to the backend Java execution.
How is 3.php-java-bridge used?
A. Download
http://php-java-bridge.sourceforge.net/pjb/download.php
Download these two files
B. Start
MV ~/download/javabridge.jar ~/php-java/
Java-jar Javabridge.jar servlet_local:8081
The following information will appear:
4. Using PHP to tune Java classes
This is the time to use the Java.inc file.
MV ~/download/java.inc ~/phptest
vi testjavabridge.php
<?phpdefine ("Java_debug", true); //Debug Settings define ("Java_hosts", "127.0.0.1:8081");d efine ("JAVA_ Log_level ", 2);require_once " Java.inc "; java_set_file_encoding (" UTF-8 ");try { $props = java ("Java.lang.System")->getproperties (); $array = java_values ($props); foreach ($array as $k = $v) { echo "$k + $v"; echo "<br>\n"; } echo "<br>\n"; class myclass { function tostring () { return "Hello php from java! "; } } $javaObject = java_closure (New myclass ()); echo "php says that java says: "; echo $javaObject; echo " <br>\n "; echo " <br>\n " echo java (" Php.java.bridge.Util ") Version; echo&nBSP; " <br>\n ";} catch (javaexception $ex) { echo "an exception occured: "; echo $ex; echo "<br>\n";}
PHP testjavabridge.php
Will output the following information similar to the following:
This information is Java information
5. Follow-up
Subsequent content will be written in a separate post explaining advanced usage.
Php-java-bridge Practice