免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
PHP中調(diào)用java

LIX. PHP / Java Integration

簡(jiǎn)介

There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.

The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.

警告

本擴(kuò)展模塊是實(shí)驗(yàn)性的。本模塊的行為,包括其函數(shù)的名稱以及其它任何關(guān)于此模塊的文檔可能會(huì)在沒有通知的情況下隨 PHP 以后的發(fā)布而改變。使用本擴(kuò)展模塊風(fēng)險(xiǎn)自擔(dān)。

需求

You need a Java VM installed on your machine to use this extension.

安裝

PECL 擴(kuò)展未綁定于 PHP 中。

在 PHP 4 中本 PECL 擴(kuò)展的源程序位于 PHP 源程序中的 ext/ 目錄下或者在上面的 PECL 連接中。 In order to use these functions you must compile PHP with Java support by using the --with-java[=DIR] where DIR points to the base install directory of your JDK. This extension can only be built as a shared extension. Additional build extensions can be found in php-src/ext/java/README.

Windows users will enable php_java.dll inside of php.ini in order to use these functions. 在 PHP 4 中本 DLL 位于 PHP Windows 執(zhí)行包中的 extensions/ 目錄下。 可以從 PHP 下載頁面或者 http://snaps.php.net/ 下載此 PECL 擴(kuò)展的 DLL 文件。

注: In order to enable this module on a Windows environment with PHP <= 4.0.6, you must make jvm.dll available to your systems PATH. No additional DLL is needed for PHP versions > 4.0.6.

運(yùn)行時(shí)配置

這些函數(shù)的行為受 php.ini 的影響。

表格 1. Java configuration options

NameDefaultChangeableChangelog
java.class.pathNULLPHP_INI_ALL 
java.homeNULLPHP_INI_ALL 
java.library.pathNULLPHP_INI_ALL 
java.libraryJAVALIBPHP_INI_ALL 
有關(guān) PHP_INI_* 常量進(jìn)一步的細(xì)節(jié)與定義參見 附錄 H。

資源類型

本擴(kuò)展模塊未定義任何資源類型。

預(yù)定義常量

本擴(kuò)展模塊未定義任何常量。

例子 1. Java Example

<?php
// get instance of Java class java.lang.System in PHP
$system = new Java(‘java.lang.System‘
);

// demonstrate property access
echo ‘Java version=‘ . $system->getProperty(‘java.version‘) . ‘<br />‘
;
echo
‘Java vendor=‘ . $system->getProperty(‘java.vendor‘) . ‘<br />‘
;
echo
‘OS=‘ . $system->getProperty(‘os.name‘) . ‘ ‘
.
             
$system->getProperty(‘os.version‘) . ‘ on ‘
.
             
$system->getProperty(‘os.arch‘) . ‘ <br />‘
;

// java.util.Date example
$formatter = new Java(‘java.text.SimpleDateFormat‘
,
                      
"EEEE, MMMM dd, yyyy ‘a(chǎn)t‘ h:mm:ss a zzzz"
);

echo
$formatter->format(new Java(‘java.util.Date‘
));
?>

例子 2. AWT Example

<?php
// This example is only intended to be run as a CGI.

$frame  = new Java(‘java.awt.Frame‘, ‘PHP‘
);
$button = new Java(‘java.awt.Button‘, ‘Hello Java World!‘
);

$frame->add(‘North‘, $button
);
$frame->validate
();
$frame->pack
();
$frame->visible = True
;

$thread = new Java(‘java.lang.Thread‘
);
$thread->sleep(10000
);

$frame->dispose
();
?>
Notes:

  • new Java() will create an instance of a class if a suitable constructor is available. If no parameters are passed and the default constructor is useful as it provides access to classes like java.lang.System which expose most of their functionallity through static methods.

  • Accessing a member of an instance will first look for bean properties then public fields. In other words, print $date.time will first attempt to be resolved as $date.getTime(), then as $date.time.

  • Both static and instance members can be accessed on an object with the same syntax. Furthermore, if the java object is of type java.lang.Class, then static members of the class (fields and methods) can be accessed.

  • Exceptions raised result in PHP warnings, and NULL results. The warnings may be eliminated by prefixing the method call with an "@" sign. The following APIs may be used to retrieve and reset the last error:

  • Overload resolution is in general a hard problem given the differences in types between the two languages. The PHP Java extension employs a simple, but fairly effective, metric for determining which overload is the best match.

    Additionally, method names in PHP are not case sensitive, potentially increasing the number of overloads to select from.

    Once a method is selected, the parameters are coerced if necessary, possibly with a loss of data (example: double precision floating point numbers will be converted to boolean).

  • In the tradition of PHP, arrays and hashtables may pretty much be used interchangably. Note that hashtables in PHP may only be indexed by integers or strings; and that arrays of primitive types in Java can not be sparse. Also note that these constructs are passed by value, so may be expensive in terms of memory and time.

Java Servlet SAPI

The Java Servlet SAPI builds upon the mechanism defined by the Java extension to enable the entire PHP processor to be run as a servlet. The primary advantage of this from a PHP perspective is that web servers which support servlets typically take great care in pooling and reusing JVMs. Build instructions for the Servlet SAPI module can be found in php4/sapi/README. Notes:

  • While this code is intended to be able to run on any servlet engine, it has only been tested on Apache‘s Jakarta/tomcat to date. Bug reports, success stories and/or patches required to get this code to run on other engines would be appreciated.

  • PHP has a habit of changing the working directory. sapi/servlet will eventually change it back, but while PHP is running the servlet engine may not be able to load any classes from the CLASSPATH which are specified using a relative directory syntax, or find the work directory used for administration and JSP compilation tasks.

目錄
java_last_exception_clear -- Clear last Java exception
java_last_exception_get -- Get last Java exception
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
php-5.x.x-Win32.zip的組織
讓IIS也能運(yùn)行PHP網(wǎng)頁
Windows 2008R2+IIS 7.5+FastCGI+PHP 5.3.3 架設(shè)配置
php5安裝
關(guān)于win xp系統(tǒng)配置php+apache+phpmyadmin的幾個(gè)問題
php5.2和apache2.2的集成配置
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服