Use DNode to implement communication between php and nodejs

Source: Internet
Author: User
Tags node server
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.