P>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.
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 PHP to access EJB enterprise-level components, 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.