Home > php教程 > PHP开发 > Compare two methods of calling Java objects in PHP

Compare two methods of calling Java objects in PHP

高洛峰
Release: 2016-12-02 10:10:27
Original
1335 people have browsed it

The Java language is powerful, so calling Java functions in php will be very useful in many cases. There are two ways 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 implementation provided by the minij2ee application server. Let's compare the characteristics of these two methods below.
1.php Java module
The PHP release version 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 more convenient. As long as you use new Java() to create a Java object, you can use it with php Java objects are called like classes. However, this method also has the following obvious shortcomings:
1. Since the Java module of php selects the most suitable Java method according to the data type of php, it cannot call Java overloaded functions.
The Java module of 2.php will load the JVM (Java Virtual Machine) in the current Web Server process, so the system overhead is huge and affects the execution efficiency of the Web Server process.
3. In some operating systems and Web Server environments, the Java module of php will freeze the Web Server process. See http://www.php.net/bugs.php?id=6122.
Due to these reasons, PHP’s Java module has never been able to be applied to actual software systems.
2. Minij2ee application server SJOP protocol implementation
Before introducing the minij2ee application server SJOP protocol implementation, let’s briefly introduce the minij2ee 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), which 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 the minij2ee application server to implement the SJOP protocol is to enable PHP to access EJB enterprise-level components. Therefore, minij2ee provides an EJB-PHP compiler that can compile EJB components into PHP classes enable EJB components to be conveniently called in PHP programs, for example:
require("Cart.php"); file://Cart.php is the PHP class definition of Cart EJB generated after compiling Cart EJB.
$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 shopping cart.
?>
Using the PHP support of the minij2ee application server, you can develop an object-oriented, stable and efficient enterprise-level application system based on PHP and J2EE technology.


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template