1

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?

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.