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. SyntaxHighli has powerful Java functions. Therefore, in many cases, it is very useful to call Java functions in php. 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:
$ System = new Java ("java. lang. System ");
Print "Java version =". $ system-> getProperty ("java. version ")."
";
?>
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 http://www.php.net/bugs.php? 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:
$ Conn = minij2ee_fetch_connection ();
Print "Java version =". minij2ee_callstatic_javaobj ($ conn, "java. lang. System", "getProperty", "java. lang. String", "java. version ")."
";
?>
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:
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 http://www.minij2ee.com/document/document_index_6_0.html.

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.