Java – Interface with running in PHP?

Interface with running in PHP?… here is a solution to the problem.

Interface with running in PHP?

I was wondering if there was any way to communicate with a running console program (preferably on Linux/Debian) via PHP. I’m currently trying to create a web interface for a small (existing) console Java program and I don’t know if there’s any way to do that. Can I “inject” a piece of code, say, a remote control module, and then use it to “remotely control” a script via PHP?
(It would be nice if you didn’t change the existing .jar file/just inject, no need to reprogram).

I appreciate every piece of advice!

Solution

If a running program doesn’t have an interface, you can’t communicate with it. However, if it does, then the answer largely depends on how the program receives external input.

If your program contains a network listening thread (daemon), you can communicate with it on the loopback interface using a raw socket from CURL or PHP.

Other ways to communicate with the program are by sharing access to files (PHP writes to files, Java reads files) or through databases.

The database would be the best choice – it is thread-safe, and both PHP and Java have excellent MySQL support (Java via JDBC).

However, if you don’t actually need to interact with a running program, just start/stop/restart it, you can use the system() function in PHP to do this.

Related Problems and Solutions