Use DNode to implement communication between php and nodejs. 1. install DNode,
1, for nodejs, run
$ Sudo npm install dnode
2. for php, use composer to install DNode php
Execute the following statement to download composer
$ Wget http://getcomposer.org/composer.phar
Create a file composer. json and enter the following statement,
{"Require": {"dnode/dnode": "0.2.0 "}}
Run the following statement to install the SDK,
$ Sudo php composer. phar install
II. use nodejs to create a simple server program, server. js
Var dnode = require ('dnode'); var server = dnode ({zing: function (n, cb) {cb (n * 100)}); server. listen (0, 7070 );
3. use php to create the client program client. php, where you need to reference the file autoload. php in the dnode folder you just installed.
Connect (7070, function ($ remote, $ connection) {// Remote is a proxy object that provides us all methods // from the server $ remote-> zing (33, function ($ n) use ($ connection) {echo "n = {$ n} \ n "; // Once we have the result we can close the connection $ connection-> end () ;});}); $ loop-> run ();?>
4. Execution Server
$ Node server. js
5. execute the client to call the server program
$ Php client. php
This will call the addition program on the server side and then output the result.
N = 3300