質問

Say I have a php application that reads JSON stock data and stores it in MySQL. Somewhere nearby on the server, I have a compiled Java (or Python, C, etc) executable that can take a set of numbers and return a set of analytics. Is there a way to call and receive data from that program from PHP without using an intermediary text file (or something similar?) I see theres http://php-java-bridge.sourceforge.net/pjb/, but would it be necessary to run a Java server like Tomcat as well?

役に立ちましたか?

解決

Technically you could use the exec function of PHP to call "java -jar YourExecutableJar.jar" and process the return value.

http://php.net/manual/en/function.exec.php

他のヒント

One "general" way is to connect them through sockets -> i.e have a listener at a port in Java that takes the set of numbers and returns the set of analytics back to the socket. The big advantage is that this is universal and can be done between any languages and between remote servers/clients as well.

Technically, any program runninng in background and accepting connections is server. Tomcat is only an example, used in numerous tutorial because it is relatively-light-and-easy-to-learn.

You can use Jetty: Shortest code to start embedded Jetty server

You can use JSON format as communication protocol (GSON library on Java side, on PHP side you already use JSON).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top