Comparison of Two Methods for php to call Java

Source: Internet
Author: User
Welcome to the Linux community forum, and interact with 2 million technical staff to enter the Java language function. It is very useful to use the Java function in php in many cases. There are two ways to use Java to speak in php: one is to use Java extension modules in php, and the other is to use SJOP provided by the mini J2EE application handler for peace talks. Below

Welcome to the Linux community forum, and interact with 2 million technical staff> the expanded Java speaking function is very useful in php in many cases. There are two ways to use Java to speak in php: one is to use Java extension modules in php, and the other is to use SJOP provided by the mini J2EE application handler for peace talks. Below

Welcome to the Linux community forum and interact with 2 million technicians>

Java's speech function grows, so it is very useful to use Java in php in many cases. There are two ways to use Java to speak in php: one is to use Java extension modules in php, and the other is to use SJOP provided by the mini J2EE application handler for peace talks. Let's take a look at the characteristics of these two methods.

1. Java module of php

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

<? Php

$ System = new Java ("java. lang. System ");

Print "Java version =". $ system-> getProperty ("java. version "). "
\ N ";

?>

The benefit of using this kind of style is the effort and convenience. As long as we use new Java () to build a Java object, we can use the same Java object as the php class. However, this style also has the following errors:

1. Because the Java module of php selects the most suitable Java Style Based on the Data Type of php, it is a function that cannot be used for Java overload.

2. the Java module of php will load the JVM (Java Virtual Machine) in the course of the current Web Server, which greatly affects the execution efficiency of the Web Server process.

3. In some operating systems and Web Server situations, the Java module of php will harden the Web Server process.

For these reasons, the Java module of php has never been applied to real software systems.

2. Implementation of the mini J2EE application handler SJOP

Before introducing the implementation of the mini J2EE application handler SJOP, let's briefly introduce the mini J2EE application handler. The mini-J2EE application server is the first J2EE application server product to support 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 agent and proxy negotiation). It is a simple and efficient Object Request agent and proxy negotiation. For example:

<? Php

$ Conn = minij2ee_fetch_connection ();

Print "Java version =". minij2ee_callstatic_javaobj ($ conn, "java. lang. System", "getProperty", "java. lang. String", "java. version "). "
\ N ";

?>

Minij2ee application server to achieve SJOP peace talks the primary purpose is to allow php to access the EJB enterprise-level components, is to minij2ee provides a EJB-PHP compiler, can compile EJB components into php class, facilitate the use of EJB components in the php track, for example:

<? Php from www.Examw.com

Require ("Cart. php"); file: // Cart. php is the php class definition generated after the Cart EJB is compiled.

$ Home = new CartHome (); file: // create the EJB Home interface.

$ 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 support of php in the mini J2EE application server, you can develop an enterprise-level application system that is object-oriented and remains unchanged and efficient based on php and J2EE technologies.

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.