The best way to send "messages" from PHP to Java on a single workstation

What is the best way to send β€œmessages” from a PHP script to a real-time Java program. PHP script and Java programs run on the same Windows workstation. Maybe some client / server? The main feature in real time ; therefore I do not want to use files.

PS: I'm going to send log messages (php) and display (java) them in the tooltip of the OS OS panel. PPS: I am a true noob in Java; this will be my first java program. :)

Thanks.

+4
source share
4 answers

You can use sockets (maybe UDP, but depends on your needs). Thus, if in the future you need to place scripts and Java programs on different computers, you can do this without changing the code.

In addition, after establishing a communication protocol between the client and server, this solution does not depend on the language. Therefore, it is easy to switch from PHP to another scripting language (the same for Java).

+2
source

It depends on how heavy your application is.

If this is your first program, and this is just a small project, then you can open the socket on the server, connect to it with the client and send data as a string, make your php program a client and program the server in java.

These are the things you can take to not do everything at a low level. But they will add weight to your program, for example, using a JSON / XML parser for serialization (make messages in bytes read from both sides), instead of using their own format.

Or, quickly and simply use an infrastructure such as JAX-RS (for people familiar with it, you may need some time to understand it, because it is not at all different from writing a simple Java program) to create a small a web service such as professionals would do.

0
source

Capabilities:

  • Submit your data as a POST to the jsp page.
  • Make your java code to read your php logs.
  • use queue systems like RabbitMQ, AciveMQ, Redis, etc.
0
source

For simplicity, use the database table as the medium of exchange. It is also easier to debug.

(This asynchrone, on one side, PHP or Java, may not be available. Performance is fast because DB-Server will store the same amount of memory.)

0
source

Source: https://habr.com/ru/post/1379351/


All Articles