如何使用Java从PHP 5 [英] How to use Java from PHP 5

查看:102
本文介绍了如何使用Java从PHP 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了不少教程使用Java从PHP,但他们似乎与海誓山盟冲突。他们中许多人说要改变php.ini文件使用一个DLL文件,但显然也有中建,在PHP 5的能力了。但是,这需要Tomcat的?我必须摆脱的Apache运行呢? <一href=\"http://php-java-bridge.sourceforge.net/pjb/installation.php\">http://php-java-bridge.sourceforge.net/pjb/installation.php说把.war文件到Tomcat的autodeploy目录中,但我没有看到任何所谓的自动部署目录中。会有人解释一步一步如何获取获取Java的东西用PHP 5和Apache的Windows机器(我使用Windows 7)上工作?

I've looked at quite a few tutorials on using Java from PHP, but they seem to conflict with eachother. Many of them say to change php.ini to use a dll file, but apparently there are "built in" capabilities in PHP 5 now. But that requires Tomcat? Do I have to get rid of Apache to run that? http://php-java-bridge.sourceforge.net/pjb/installation.php says to put the .war file into Tomcat's autodeploy directory, but I don't see any directory called "autodeploy". Would someone explain step-by-step how to get get Java stuff working on a Windows machine (I'm using Windows 7) with PHP 5 and Apache?

推荐答案

您可能会发现关于如何使用Java类从PHP网页应用,它并不能帮助所有吨无用的,过时的信息。大约一年前,我曾遇到过类似的问题,我发现,这是不够成熟的生产中使用的唯一途径是PHP / Java桥 - 你Sourceforge上发现之一。它比人们所预料的好,并不需要Java(但是,如果你知道的Java,你应该考虑编写用于此目的的网络服务,并使用它在PHP端)。

You will probably find tons of useless and outdated information regarding how to use Java classes from your PHP webapp which doesn't help at all. About a year ago I had faced a similar problem and I found out that the only way that is mature enough to use in production is PHP/Java Bridge -- the one you found on Sourceforge. It works better than one might expect and doesn't require knowledge of Java (however if you do know Java, you should consider writing a Web-service for this purpose and consume it on the PHP-side).

桥的文档不是很明显,但是请记住,你应该坚持下去,而不是读描述不同方法的其他资源 - 不要混为一谈,也就是说,你不必安装任何PHP的扩展或水木清华 - 他们都涉及到另一个(通常是过时的和不支持的)的方式从PHP调用Java

The documentation of the Bridge is not very obvious, however remember you should stick with it and not read other resources that describe different methods - don't mix things up, i.e. you don't have to install any PHP-extensions or smth -- all of them relates to another (usually outdated and unsupported) ways to call Java from PHP.

PHP / Java桥是一种网络协议,所以你需要在你的PHP端的唯一的事情是确保allow_url_include在你的php.ini启用

PHP/Java Bridge is a network protocol, so the only thing you need on your PHP-side is to ensure "allow_url_include" is enabled in your php.ini

这是你必须让PHP / Java桥绑定到一个自由港,听连接Java端。那么你的PHP的应用程序将能够做桥的代理文件的require_once,这将是可用的端口上。这就是它,你可以实例,并使用该代理对象大桥从你的PHP脚本调用透明的Java类(它将序列化和转移呼叫和成果在幕后)。

From the Java side you have to get PHP/Java Bridge bound to a free port and listen to connections. Then your PHP-app will able to do "require_once" of the Bridge's proxy file which will be available on that port. That's it and you can instantiate and call Java classes transparently from your PHP script using that proxy Bridge object (it will serialize and transfer calls and results behind the scenes).

有两种选择怎么弄桥和其绑定到一些本地端口。

There are two options how get the Bridge up and bind it to some local port.

1)复杂的:建立一个Tomcat,创建与大桥本身和你想使用图书馆战争文件。这里描述是这样的:

1) complex one: setup a Tomcat, create a war file with the bridge itself and the library you'd like to use. This way is described here:

<一个href=\"http://php-java-bridge.sourceforge.net/pjb/webapp.php\">http://php-java-bridge.sourceforge.net/pjb/webapp.php

要部署战成Tomcat安装简单地把战成Tomcat的WebApp文件夹并重新启动。

To deploy the war into your Tomcat installation simply put the war into Tomcat's webapp folder and restart it.

2)容易之一:打包罐,而不是战争和运行它(它将使用嵌入式Web服务器,所以你就不必安装Tomcat和部署的任何东西)。走这条路参考这个网页:

2) easier one: package a jar instead of war and run it (it will use embedded web-server, so you won't have to install Tomcat and deploy anything). To go this way refer this page:

<一个href=\"http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php\">http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php

这两种方法会为你工作(不要在桌面字看第二个选项,这样将正常工作与你的PHP Web应用中)。

Both ways will work for you (don't look at the "desktop" word at the second option, this way will work fine with your PHP webapp as well).

请参阅如何将示例部分(obvously)在使用的例子。你也可以参考我,讨论使用PHP / Java桥用Java嵌入式数据库Neo4j的小PHP客户端。然而这个样本可能更复杂,它的目的是要部署到Tomcat,反正你可以有一个想法如何实例化和使用的类从它:

Refer to examples on how to use it at the "Examples" section (obvously). Also you can refer to my small PHP client that talks to Neo4J embedded database in Java using PHP/Java Bridge. However this sample might be more complex and it was intended to be deployed to the Tomcat, anyway you can have an idea how to instantiate and use classes from it:

<一个href=\"https://github.com/coffeesnake/neo4j-php-wrapper\">https://github.com/coffeesnake/neo4j-php-wrapper

这篇关于如何使用Java从PHP 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆