Home > Backend Development > PHP Tutorial > Two methods of calling java classes in PHP_PHP tutorial

Two methods of calling java classes in PHP_PHP tutorial

WBOY
Release: 2016-07-20 11:04:48
Original
791 people have browsed it

The Java language is powerful, so calling Java functions in PHP will be useful in many situations. 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.
Java module of 1.php
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")."
";
?>
Use this method The advantage is that it is more convenient. As long as you use new Java() to create a Java object, you can call the Java object just like the PHP class. 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 access to EJB enterprise-level components in php, so minij2ee provides An EJB-PHP compiler can be used to compile EJB components into PHP classes, so that EJB components can 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. For a more detailed introduction to PHP-J2EE technology, please visit http://www.minij2ee.com/document/document_index_6_0.html.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445176.htmlTechArticleThe Java language is powerful, so in many cases it will be very useful to call Java functions in php. There are two ways to call Java language in php. One is to use the Java extension module in 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template