Php-java-bridge Practice

Source: Internet
Author: User

  • 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

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.