开发者

PHP get data or interact with a running Java process. (I think different than PHP/Java bridge)

开发者 https://www.devze.com 2023-02-13 18:10 出处:网络
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 informatio

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.


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 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:

<?php
    include_once("Java.inc");

$i1 = new Java("your.class", "1");
$i2 = new Java("your.class", "2");
$i3 = $i1->add($i2);
echo $i3->toString() . "\n";
?>

See Java.inc. And edit your java code to contain the following line:

static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner.getInstance("9267");


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.


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号