php 与 java(一)

 更新时间:2016年11月25日 16:33  点击:1726
JAVA是个非常强大的编程利器,它的扩展库也是非常的有用,这篇教程,主要讲述怎样使用PHP调用功能强大的JAVA 类库(classes)。为了方便你的学习,这篇教程将包括JAVA的安装及一些基本的例子。
windows下的安装
第一步:安装JDK,这是非常容易的,你只需一路回车的安装好。然后做好以下步骤。
在 Win9x 下加入 :“PATH=%PATH%;C:jdk1.2.2in” 到AUTOEXEC.BAT文件中
在 NT 下加入 “;C:jdk1.2.2in”到环境变量中。
这一步是非常重要的,这样PHP才能正确的找到需调用的JAVA类。
第二步:修改你的PHP.INI文件。
[java]
extension=php_java.dll
java.library.path=c:webphp4extensions
java.class.path="c:webphp4extensionsjdk1.2.2php_java.jar;c:myclasses"
在PHP.INI中加入extension=php_java.dll
并在[java]中,设定好java.class.path,让它指向php_java.jar,如果你使用新的JAVA类,你也应该存入这个路径,在这篇例子中,我们使用c:myclasses这个目录。
第三步:测试环境,创建如下PHP文件:

$system = new Java("java.lang.System");
print "Java version=".$system->getProperty("java.version")."
";
print "Java vendor=".$system->getProperty("java.vendor")."
";
print "OS=".$system->getProperty("os.name")." ".
$system->getProperty("os.version")." on ".
$system->getProperty("os.arch")."
";
$formatter = new Java("java.text.SimpleDateFormat","EEEE,
MMMM dd, yyyy 'at' h:mm:ss a zzzz");
print $formatter->format(new Java("java.util.Date"))." ";
?>
如果你正确安装了,你将会看到以下信息:
Java version=1.2.2
Java vendor=Sun Microsystems Inc.
OS=Windows 95 4.10 on x86
Wednesday, October 18, 2000 at 10:22:45 AM China Standard Time
这样,我们就已经成功的建立起了可以使用JAVA类的PHP运行环境,我们可以开始我们接下去的课程了。
作者:井中月
转载:
PHP中有许多与文件系统有关的函数,这些函数不仅可以打开文件,还可以显示目录中的内容、移动文件和其他一些功能,许多人甚至用PHP开发基于互联网的文件资源管理器。
下面的脚本样例可以显示一个目录清单,注释已经包含在代码中:
<? / Compiling php with crypt()
author:
Daniel Beulshausen
updated:
14.10.2000


This quick tutorial shall help you to compile php with support for the crypt() function, because it's not correct that if you use windows you can't use crypt().
It is however correct that libcrypt isn't available by default on windows, but you can use the libary from our download section.
Extract the zip and move crypt.h to your include folder, and the needed libary (release or debug) to your libary folder (tools -> options -> folders).
Load the php workspace, and add crypt.c (can be found in ext/standard/) to the php4dllts group (you can put crypt.c to Function Modules -> Source Files).
Now edit the link options of the php4dllts project, and add libcrypt to the link libaries, note that we compiled a release and a debug libary, please use only release for the release builds, and the debug libary for debug builds!
Now edit config.w32.h (located in main/), edit it and change the needed defines:
#define HAVE_CRYPT 1
#define HAVE_CRYPT_H 1
This should do the trick, and it'll build you php with the crypt() function. 
read_exif_data
(PHP 4 )
read_exif_data -- Reads header information stored in TIFF and JPEG images
Description
array exif_read_data ( string filename, string sections, bool arrays, bool thumbnail)
Note: The read_exif_data() function is an alias for exif_read_data().
See also exif_thumbnail().
User Contributed Notes
read_exif_data
inq@inq.dhs.org
03-Jan-2001 03:52
Each of my jpeg files are over 1 meg, and read_exif_data seems to read the
whole file and it's very slow. So I wrote a function to read only the
beginning of each file:
function read_exif_data_quick($path) {
$tmpfile = "/tmp/read_exif_data_quick.tmp_file";
$in = fopen($path, "r");
$out = fopen($tmpfile,"w");
fwrite( $out, fread( $in, 15000 ) );
fclose($in);
fclose($out);
return read_exif_data($tmpfile);
}
And so far it works for all of my jpegs (taken with my digital camera).
garbage@sunflowerroad.com
06-Jul-2001 05:33
I started drooling when I saw that php could read the exif information
automatically for me. Then I found out that read_exif_data is NOT
compiled into the standard win32 build (think about including it please!).
To get around this I found the following program that runs from the
command line and works really well.
it's actually a set of utilities that will even allow you to put exif data
into images.
It's freeware, but the license says no commercial use without written
permission.
http://www.users.bigpond.com/hughthomas/exif.html
garbage@sunflowerroad.com
06-Jul-2001 05:34
By the way, it works under linux or win32
ibaldin@anr.mcnc.org
21-Aug-2001 11:43
Perl Image::Info module is capable of reading EXIF tags (places them into
an associative array). You can write a simple script to use the module and
it will extract all or only required tags out of a jpeg file.
作 者: 徐永久
我们知道 Zend 有免费的优化引擎针对 PHP 而作,但是 FreeLAMP 这次采用的是一个叫做 PHP Accelerator 的缓冲产品。
我们在 “LAMP 加速” 这篇文章中阐述过加速的几种办法,其中提到了 PHP Accelerator,它的安装方法十分简单,但是需要去他的网站获取一个激活键。
一、下载:
http://www.php-accelerator.co.uk/download.php
二、获取激活键并安装:
http://www.php-accelerator.co.uk/activate.php
注册自己的 SERVER_NAME 后,你会得到下面的提示:
Your key for www.freelamp.com is 8edfd13946c96309244fcca309415902
Now you must set the key for www.freelamp.com in your site configuration.
For single domains not using virtual hosts
The key can be set in the php.ini file as follows:
# PHPA key for www.freelamp.com
#
phpa.registration_key = 8edfd13946c96309244fcca309415902
For domains setup as a virtual host
Add the key to the domain specific section for your web server.
# www.freelamp.com VHost entry
#
ServerName www.freelamp.com
# ... (other vhost specific config)
# php settings
php_value phpa.registration_key 8edfd13946c96309244fcca309415902
# also enable phpa if set to off in the php.ini (the default is on)
php_value phpa 1
具体的 phpa 值的设置,可以参考软件随带的 CONFIGURATION 文件的配置。
由于大多数网站是虚拟主机配置,所以,建议采用 php_value phpa. 的方式设置。
例如:
php_value phpa.tweaks off
php_value phpa.cache_dir /tmp
php_value phpa.file_perms 400
php_value phpa.ignore_files "/index.php, /a/test.php"
# php_value phpa.ignore_dirs "/data/WWW/site1/,/cache/"
php_value phpa.shm_size 8
php_value phpa.shm_key 0xc0deb00
php_value phpa.shm_perms 664
三、设置 php.ini
假设我们把下载后的文件解开到 /usr/local/php ,那么在 php.ini 中加入:
zend_extension=/usr/local/php/php_accelerator_1.2p2.so
并注释掉原来的 Zend 优化引擎:
# zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
[!--infotagslink--]

相关文章