So far I used websockets to communicate between nodejs and php. I created a websocket server in nodejs that is listening on some custom port.
Then in the php script I used stream_socket_client()
and related functions to connect as client. Then whenever I wanted something from the server I would send a message and expect a response with the data (as json). Then it would build the html to display that data to the user.
This works, however it does not seem natural and I was wondering if there are better options. Websockets are intended for the web as the name implies, but I am using it for local server and script
I should mention that the server needs to be able to communicate with multiple clients at the same time, because a website can have multiple visitors. The nodejs websocket modules offer this capability. But it does not need to keep connections alive, because the php script only does its thing and stops.
source https://stackoverflow.com/questions/70250119/options-for-communication-between-nodejs-server-and-php-website
No comments:
Post a Comment