How to use PHP to call the Java language _ PHP Tutorial

Source: Internet
Author: User
Tags php compiler
Quickly learn how PHP calls Java. PHP calls Java language 1. Java Module of php the PHP release version contains a Java extension module that can be used to call Java objects, such :? Php $ systemnewJava (java. lang. System); printJava

PHP calls Java language 1. Java Module of php

The php release contains a Java extension module that can be used to call Java objects. for example:

  1. <? Php
  2. $ System = new Java ("java. lang. System ");
  3. Print "Java version =". $ system->
    GetProperty ("java. version ")."

  4. /N ";
  5. ?>

The advantage of using this method is that it is convenient. you only need to use new Java () to create a Java object, and you can call the Java object like the php class. However, this method also has the following obvious disadvantages:

1. because the Java Module of php selects the most suitable Java method based on the data type of php, it cannot call Java overload functions.

2. the Java Module of php will load the JVM (Java virtual machine) in the current Web Server process. Therefore, the system overhead is extremely high, which affects the execution efficiency of the Web Server process.

3. in some operating systems and Web Server environments, the Java Module of php will harden the Web Server process.

For these reasons, the Java Module of php has never been applied to the actual software system. ---Www.002pc.com

PHP calls Java language 2. implementation of the mini J2EE application server SJOP protocol

Before introducing the implementation of the mini J2EE application server SJOP protocol, let's briefly introduce the mini J2EE application server. The minij2ee application server is the first J2EE application server product that supports php, enabling php to be used to develop enterprise-level application systems. The full name of SJOP is Sample Java ORB Protocol (simple Java Object request proxy Protocol). It is a simple and efficient object request proxy Protocol. For example:

 
 
  1. < ?php
  2. $conn=minij2ee_fetch_connection();
  3. print "Java version=".minij2ee_
    callstatic_javaobj($conn,"java.lang.
    System","getProperty","java.lang.
    String","java.version")."

  4. /n";
  5. ?>

The main purpose of implementing the SJOP protocol on the minij2ee application server is to enable php to access EJB enterprise components. Therefore, minij2ee provides a EJB-PHP compiler that can compile EJB components into php classes, this allows php programs to conveniently call EJB components, for example:

 
 
  1. <? Php
  2. Require ("Cart. php ");
  3. File: // Cart. php is to compile Cart
    The php class definition of Cart EJB generated after EJB.
  4. $ Home = new CartHome ();
  5. File: // create the Home interface of the EJB.
  6. $ Objref = $ home-> create ($ cart_name );
  7. File: // create Cart EJB.
  8. $ Cart = new Cart ($ objref); $ cart-> add ("some goods ");
  9. File: // add an item to the shopping cart.
  10. ?>

By calling the Java language method in PHP on the mini J2EE application server, you can develop an enterprise-level application system that is object-oriented and stable based on php and J2EE technologies.


The released version of php contains a Java extension module that can be used to call Java objects, such :? Php $ system = new Java (java. lang. System); printJava...

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.