简体   繁体   中英

Php -> Node.js transport/bridge

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM