Two Methods for PHP to call java classes

Source: Internet
Author: User
Tags php compiler

The Java language is powerful, so it is very useful to call Java functions in php in many cases. There are two methods to call the Java language in php: one is to use the Java extension module in php, and the other is to use the SJOP protocol provided by the minij2ee application server. Next we will compare the features of the two methods.
1. Java module of php
The php release contains a Java extension module that can be used to call Java objects. For example:
<? Php
$ System = new Java ("java. lang. System ");
Print "Java version =". $ system-> getProperty ("java. version"). "<br> ";
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. See Id = 6122.
For these reasons, the Java module of php has never been applied to the actual software system.
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:
<? Php
$ Conn = minij2ee_fetch_connection ();
Print "Java version = ". minij2ee_callstatic_javaobj ($ conn, "java. lang. system "," getProperty "," java. lang. string "," java. version "). "<br> ";
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:
<? Php
Require ("Cart. php"); file: // Cart. php is the php class definition of Cart EJB generated after Cart EJB is compiled.
$ Home = new CartHome (); file: // create the Home interface of EJB.
$ Objref = $ home-> create ($ cart_name); file: // create Cart EJB.
$ Cart = new Cart ($ objref );
$ Cart-> add ("some goods"); file: // add an item to the cart.
With the php support of the minij2ee application server, you can develop an enterprise-level application system that is object-oriented and stable and efficient based on php and J2EE technologies. For more information about PHP-J2EE technology, visit

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: 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.