Is there any way to send string or Json data from php to nodeJS server.
My project use php(Nginx server serves it). And nodeJs server(8080 port, NowJS) is running as background for realtime Pub/Sub update.
When a user write a message, database(Mysql) also is updatd using php. And the change have to send to nodeJS(NowJS, 8080 port) server for realtime updating.
Realtime Update Mechanism : user writes -> php save it in mysql db -> php send info to nodeJS -> nodeJS send the change all subscribers -> others can notice it in realtime.
So my question is, Is there any way to send the changes from php to NodeJS server? I am a nodeJS newbie. Any comments welcomes~ ^^;
Any reason you can't use curl?
$ch = curl_init('http://yournodehost/path');
curl_exec($ch);
Depending on the requirements of your request you can set the appropriate curl options.
Node.js is pretty flexible, but if you've implemented an http server with it, then your PHP can use file_get_contents to fetch a URL. http://php.net/manual/en/function.file-get-contents.php . This is only for a GET method, you'll have to encode your json appropriately...
As a side note, you might want to have your server modify the database, instead of mixing the functionality half in the PHP and half in the node.js server. That might help keep all the related work in one place, possibly easier to maintain, debug, expand, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With