PHP 获取数据或与正在运行的 Java 进程交互。 (我认为与 PHP/Java 桥不同)
我有一个 apache2 网络服务器,安装了 php 并正在运行。我想知道是否有任何方法可以让 PHP 脚本访问不断运行的 Java 程序,主要是为了获取进程跟踪的信息。 Java 程序不是 Web 应用程序,也不是在 apache 服务器内运行。这是一个单独的程序。
我一直在研究 PHP/Java Bridge 系统,它们似乎所做的就是让你从 PHP 运行 Java 程序,反之亦然,这不是我需要的。我可以想出一种方法,通过在本地主机上运行的 Web 服务和 SOAP 来实现此目的,但如果有一种方法可以避免这种情况,并且我可以直接访问 Java 程序,那么我可以让我的 Web 应用程序运行得更快。
我试图与之“交谈”的 Java 应用程序是我编写的一个程序,因此如果需要在 Java 程序中进行某些设置,我可以访问源代码以进行必要的更改。
预先感谢,我一直在寻找类似的东西。
I have an apache2 webserver with php installed and working. I am wondering if there is any way I can get a PHP script to access a Java program that is constantly running, mostly to just get information that the process keeps track of. The Java program is not a webapp or running within the apache server. It is a separate program.
Ive been looking into PHP/Java Bridge systems, and all they seem to do is let you run Java programs from PHP and vice-a-versa, which is not what I need. I can think of a way to do this via a web service and SOAP running on localhost, but if there is a way to avoid this and I can gain direct access to the Java program, I could get my webapp to run much faster.
The Java app that I am trying to "talk to" is a program that I wrote so I have access to the source code to make the necessary changes if something within the Java program needs to be set up.
Thanks in advance, I've been looking all over for something like this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要以一种或另一种方式与 Java 进程进行通信。由于 Web 服务太繁重,您可以简单地使用自定义文本或二进制协议通过套接字进行通信。
或者,您也可以让 Java 程序每 n 秒写入一个数据库,并在 PHP 脚本中从数据库中读取数据。
编辑:
看看 http://www.php.net/manual/en/sockets .examples.php 用于 PHP 中的套接字客户端示例。
看看 http://download.oracle.com/javase/tutorial/networking /sockets/clientServer.html 用于 Java 中的服务器套接字示例。
You'll need to communicate with the Java process in one way or another. As a web service is too heavy, you could simply communicate over a socket with a custom text or binary protocol.
Or you could also perhaps make the Java program write to a database every n seconds, and read from the database in your PHP script.
EDIT :
Look at http://www.php.net/manual/en/sockets.examples.php for a socket client example in PHP.
Look at http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html for a server socket example in Java.
PHP/Java Bridges 允许您从 PHP 调用正在运行的 Java 程序。
阅读:http://en.wikipedia.org/wiki/PHP/Java_Bridge
阅读: http://php-java-bridge.sourceforge.net/pjb/desktop -apps.php
桥实际上使用本地套接字通信,来自 faq :
参见Java.inc。
并编辑您的 java 代码以包含以下行:
PHP/Java Bridges let you call a running Java program from PHP.
Read: http://en.wikipedia.org/wiki/PHP/Java_Bridge
Read: http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php
The bridges actually use local socket communication, from the faq:
See Java.inc.
And edit your java code to contain the following line:
嘿,那么基本上你需要从 php 运行 java 应用程序并从 java 应用程序获取响应?
如果是这样的话 - 我看不到 php/java-bridge 有任何问题。例如,我已成功运行 java 加密方法以在 php 中进行自定义加密。
Hey, so basically you need to run java application from php and get response from java application?
If its that so - I can't see any problem fro php/java-bridge. For example I've successfully run java encryption method for custom encryption in php.
您可能会研究 Quercus/Resin。 PHP 在 Java Web 服务器上的 Java 内部运行。您可以像调用 PHP 函数/命令一样调用 Java 代码。不支持所有 PHP 命令,但大多数命令都支持。例如,您可以在 Quercus 下运行 WordPress。
http://www.caucho.com/resin-3.0/quercus/
You might look into Quercus/Resin. PHP runs inside Java on a Java web server. You can call Java code as if it was PHP functions/commands. All PHP commands are not supported, both most are. For example, you can run WordPress under Quercus.
http://www.caucho.com/resin-3.0/quercus/