Quickly master PHP calling Java language methods_PHP tutorial

WBOY
Release: 2016-07-15 13:33:55
Original
717 people have browsed it

PHP calls Java language 1.php’s Java module

The php release version contains a Java extension module, Can be used to call Java objects, for example:

  1. < ?php
  2. $system=newJava("java.lang.System");
  3. print "Java version=".$ system->
    getProperty("java .version")."
  4. <br> /n";
  5. ?> 🎜>
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 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 based on the data type of php, Java overloaded functions cannot be called.

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.

Due to these reasons, PHP’s Java module has never been able to be applied to actual software systems. ---www.002pc.com

PHP calls Java language 2.minij2ee application server SJOP protocol implementation

Before introducing the minij2ee application server SJOP protocol implementation, let’s make it simple 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:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li>
<li>
<span>$</span><span class="attribute">conn</span><span>=</span><span class="attribute-value">minij2ee_fetch_connection</span><span>();  </span>
</li>
<li class="alt">
<span>print "Java </span><span class="attribute">version</span><span>=".minij2ee_<br>callstatic_</span><span class="attribute-value">java</span><span>obj($conn,"java.lang.<br>System","getProperty","java.lang.<br>String","java.version")."   </span>
</li>
<li>
<span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>/n";  </span>
</li>
<li class="alt">
<span class="tag">?></span><span>   </span>
</li>
</ol>
Copy after login
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 EJB components are compiled into PHP classes, so that EJB components can be conveniently called in PHP programs. For example:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>require("Cart.php");   </span></li><li class="alt"><span>file://Cart.php是编译Cart <br />EJB后生成的Cart EJB的php类定义。</span></li><li class="alt"><span>$</span><span class="attribute">home</span><span>=</span><span class="attribute-value">new</span><span> CartHome();  </span></li><li><span>file://创建EJB的Home接口。</span></li><li><span>$</span><span class="attribute">objref</span><span>=$home-</span><span class="tag">></span><span>create($cart_name); </span></span></li>
<li><span>file://创建Cart EJB。  </span></li>
<li class="alt">
<span>$</span><span class="attribute">cart</span><span>=</span><span class="attribute-value">new</span><span> Cart($objref);$cart-</span><span class="tag">></span><span>add("some goods");</span>
</li>
<li class="alt"><span>file://向购物车中添加一个物品。  </span></li>
<li>
<span class="tag">?></span><span>  </span>
</li>
</ol>
Copy after login
Use PHP of minij2ee application server to call Java language methods, and you can develop Develop an object-oriented, stable and efficient enterprise-level application system based on PHP and J2EE technology.


http://www.bkjia.com/PHPjc/446029.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446029.htmlTechArticlePHP calls Java language 1. The Java module of php. The php release version contains a Java extension module that can be used to call Java object, for example: ?php $ system = new Java(java.lang.System); printJava...
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