PHP调用Java语言一.php的Java模块
php发布版中包含一个Java扩展模块,可以用来调用Java对象,例如:
- ?php
-
$system=new Java("java.lang.System");
-
print "Java version=".$system->
getProperty("java.version")."
-
br>/n";
-
?>
使用这种方法的优点是比较方便,只要用new Java()来创建一个Java对象,就可以同php类一样来调用Java对象。但是这种方法也有以下明显的缺点:
1.由于php的Java模块根据php的数据类型选择最适合的Java方法,因此无法调用Java过载的函数。
2.php的Java模块将在当前Web Server的进程中载入JVM(Java虚拟机),因此系统开销极大,影响Web Server进程的执行效率。
3.在某些操作系统和Web Server环境中,php的Java模块将使Web Server进程僵死。
由于这些原因,php的Java模块一直无法应用到实际的的软件系统中。---www.002pc.com
PHP调用Java语言二.minij2ee应用服务器SJOP协议实现
在介绍minij2ee应用服务器SJOP协议实现之前,先简单介绍一下minij2ee应用服务器。minij2ee应用服务器是第一款支持php的J2EE应用服务器产品,使php能够用于开发企业级应用系统。SJOP全称是Sample Java ORB Protocol(简单Java对象请求代理协议),是一种简单高效的对象请求代理协议。比如:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <ol class = "dp-xml" >
<li class = "alt" ><span><span class = "tag" ><span> ?php </span></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 class = "tag-name" >br</span><span class = "tag" >></span><span>/n"; </span></span></li>
<li class = "alt" >
<span class = "tag" >?></span><span> </span>
</li>
</ol>
|
Copier après la connexion
minij2ee应用服务器实现SJOP协议的主要目的是使php中能够访问EJB企业级组件,因此minij2ee提供了一个EJB-PHP编译器,可以把EJB组件编译成php的类,使php程序中能够方便的调用EJB组件,例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <ol class = "dp-xml" >
<li class = "alt" ><span><span class = "tag" ><span> ?php </span></span></span></li>
<li><span> require ( "Cart.php" ); </span></li>
<li class = "alt" ><span>file:
<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:
<li>
<span>$</span><span class = "attribute" >objref</span><span>= $home -</span><span class = "tag" >></span><span>create( $cart_name ); </span>
</li>
<li><span>file:
<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:
<li>
<span class = "tag" >?></span><span> </span>
</li>
</ol>
|
Copier après la connexion
使用minij2ee应用服务器的PHP调用Java语言方法,就可以开发出基于php和J2EE技术的,面向对象的,稳定高效的企业级应用系统。