Php -> Node.js transport/bridge

1.2k Views Asked by At

Tell me, please, how to organize a correct transport data from PHP to Node.js?

I tried to use the library dNode, but it does not work in conjunction with socket.io.

Example:

io.sockets.on('connection', function(socket) {
    var server = dnode({
        setMeta: function(data, callback) {
            // not working
        }
    });
    server.listen(dPort);
});

Advise the alternative?

1

There are 1 best solutions below

0
On

To send data from PHP to NodeJS can use the following:

<?php

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/user/img.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost:8082/test'); /* Nodejs */
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?>

More info here.

In app.js

app.post('/test', function(req, res){
    console.log("name: " + req.body.name);
...

I hope that is helpful.