Home > php教程 > PHP源码 > body text

PHP and java communication plug-in

大家讲道理
Release: 2016-11-08 11:46:32
Original
1252 people have browsed it

Since the company's project needed something to interface with Java and didn't want to use webservice, I made a PHP module. After struggling for a long time to compile it, I still couldn't get through it. I simply modified the source code. After testing, it worked. Attached is also a copy of my installation record. Let everyone avoid some detours
In addition, this thing needs to install java. Just go to the official website to download it. The latest version 1.8

The system version is centos 7 x64
PHP 5.4.x

http://pan.baidu.com/s/1i47UYl3 The download address of the version package. Since osc does not allow transmission, I put it in Baidu network disk.

tar -xzf php-java-bridge-5.4.3.1.new.tar.gz
cd php-java-bridge-5.4.3.1
/usr/local/php/bin/phpize
./configure --disable-servlet --with-java=/usr/java/jdk1.8.0_91,/usr/java/jdk1.8.0_91/jre --with- php-config=/usr/local/php/bin/php-config
make
make install


/usr/java/jdk1.8.0_91/jre/bin/java -classpath /usr/local/php/lib/ php/extensions/no-debug-zts-20100525/JavaBridge.war TestInstallation
This command is best started at boot


php.ini Added
extension=java.so
[java]
;java.hosts = 127.0.0.1 :8080
;java.servlet = On ;; Off, On or User
java.log_level = 3

Restart php-fpm apache nginx

复制Java.inc放到网站目录里面调用就OK了
/usr/local/php/lib/php/extensions/no-debug-zts-20100525/java/Java.inc
修改:
define ("JAVA_HOSTS", "127.0.0.1:8080");
// define ("JAVA_PERSISTENT_SERVLET_CONNECTIONS", true);
// define ("JAVA_PREFER_VALUES", 1);
define ("JAVA_DEBUG", false);
define ("JAVA_PIPE_DIR", "/data/test/java-tmp"); //这个是缓存文件地址
Copy after login
// http://c.3viso.cn/java.php  这是一个测试小程序
#!/usr/bin/php
 
<?php
require_once("Java.inc");
 
$system=new java("java.lang.System");
print "Java version=".$system->getProperty("java.version")." ";
$str=new Java("java.lang.String");
echo $str;
Copy after login


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template