Centos 5下php-java-bridge扩展安装与配置

由于公司业务需要通过招商银行进行网上支付,但是由于PHP不能调用招行的Java校验码而导致无法进行下一步支付,所以就进行php-java-brige的安装。

系统环境

[root@app4 ~]# cat /etc/redhat-release 
CentOS release 5.11 (Final)
[root@app4 ~]# /usr/local/webserver/php/bin/php -v
PHP 5.2.14 (cli) (built: Apr 16 2012 16:45:06) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
 with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
 with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies
<a href="https://www.olinux.org.cn/tag/php-java-bridge" title="查看与 php-java-bridge 相关的文章"target="_blank">php-java-bridge</a>-5.4.4.2

php-java-bridge下载地址:http://netix.dl.sourceforge.net/project/php-java-bridge/RHEL_FC%20SecurityEnhancedLinux/php-java-bridge_5.4.4.2/php-java-bridge_5.4.4.2.tar.gz

php-java-brige是php众多拓展模块(功能)中的一个,安装此模块之后,PHP就能自动调用Java语言编写的文件了。

What is the PHP/Java Bridge?

The PHP/Java Bridge is an implementation of a streaming, XML-based network protocol, which can be used to connect a native script engine, for example PHP, Scheme or Python, with a Java virtual machine. It is up to 50 times faster than local RPC via SOAP, requires less resources on the web-server side. It is faster and more reliable than direct communication via the Java Native Interface, and it requires no additional components to invoke Java procedures from PHP or PHP procedures from Java.

Centos 5下php-java-bridge扩展安装与配置

J2EE back end clustering and Apache load balancing are supported as well as running PHP scripts within JSP, JSF or other frameworks.

The bridge uses "continuation passing" to invoke procedures/methods from each environment. Although this may be unusual, it is a fast and reliable mechanism to connect different script environments.

安装java

yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel -y

配置环境变量/etc/profile后面加入

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar

[root@app4 ~]# source /etc/profile
[root@app4 ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64
安装php-java-bridge扩展

[root@app4 ~]#cd /data/soft/
[root@app4 soft]#tar zxvf php-java-bridge_5.4.4.2.tar.gz
[root@app4 soft]#cd php-java-bridge-5.4.4.2/
[root@app4 php-java-bridge-5.4.4.2]#/usr/local/webserver/php/bin/phpize
[root@app4 php-java-bridge-5.4.4.2]#./configure --with-java=$JAVA_HOME,$JAVA_HOME/jre --with-php-config=/usr/local/webserver/php/bin/php-config
[root@app4 php-java-bridge-5.4.4.2]#make
[root@app4 php-java-bridge-5.4.4.2]#make install

配置php-java-bridge
编辑php.ini在最后添加

java.java_home="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64"
java.java="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.101.x86_64/jre/bin/java"
java.log_file="/var/log/php-java-bridge.log"
java.classpath="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/JavaBridge.jar"
java.libpath="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
java.log_level="2"
extension="java.so"

保存重启php后运行phpinfo查看关于java bridge的扩展信息验证是否成功
安装碰到过的坑
make时提示/data/soft/php-java-bridge-5.5.4.1/init_cfg.h:44:39: note: in expansion of macro ‘EXT’
#define EXT_GLOBAL(fkt) EXT_EXPAND( , EXT, _, fkt)
^
/data/soft/php-java-bridge-5.5.4.1/java.c:302:3: note: in expansion of macro ‘EXT_GLOBAL’
EXT_GLOBAL(destroy_cfg) (EXT_GLOBAL(ini_set));
^
make: *** Error 1
解决办法:php版本过高,降低php版本至5.2.14
最初安装时就碰到这个坑,当初php版本为5.5.25,为了解决这个坑,java版本从1.6.0变更为1.7.0,php-java-bridge版本从php-java-bridge_6.2.1降为php-java-bridge_5.5.4.1再降php-java-bridge_5.5.2均未解决,最后降低php版本解决此问题
在启动Javabridge.jar的前提下,PHP才能自动调用Java接口,启动命令nohup java -jar /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/Javabridge.jar SERVLET:8080 3 JavaBridge.log &

您可以选择一种方式赞助本站

支付宝转账赞助

支付宝扫一扫赞助

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

图片 表情