One, install Dnode,
1, for Nodejs, execute
$ sudo npm install dnode
2, for PHP, using composer to install Dnode PHP
Execute the following statement to download composer
Create a file Composer.json, and then fill in the following statement,
{"Require": {"Dnode/dnode": "0.2.0"}}
Execute the following statement installation,
$ sudo php Composer.phar Install
Second, create a simple server program with Nodejs, Server.js
var Dnode = require (' Dnode '); var server = Dnode ({zing:function (n, CB) {CB (n *)}}); Server.listen (7070);
Third, the use of PHP to create a client program client.php, which need to refer to the Dnode folder just installed inside the file autoload.php
<?php//Connect to Dnode server running in Port 7070 and call//Zing with Argument 33require ' Lib/vendor/autoload. PHP ';//This was the class we ' re exposing to dnodeclass temp{//Compute The client ' s temperature and stuff that value I Nto the callback public function temperature ($CB) {}} $loop = new React\eventloop\streamselectloop (); $dnode = new Dnode\dnode ($loop, New Temp ()); $dnode->connect (7070, function ($remote, $connection) {//Remote is a proxy object T Hat provides us all methods//from the server $remote->zing (for function ($n) use ($connection) {echo "n = {$n}\n "; Once we have the result we can close the connection $connection->end (); });}); $loop->run ();? >
Four, perform server-side
$ node Server.js
Five, execute client Invoke server-side program
$ PHP client.php
This invokes the server-side add program and outputs the result
n = 3300