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.
source share