The easiest way I use is to pass your PHP data to node using HTTP post or get, here is my code to send data from PHP to the node.
// Node Side
var express = require('express');
express = express();
var bodyParser = require('body-parser');
express.use(bodyParser.json());
express.post('/get_php_data', function (req, res) {
// php array will be here in this variable
var data = req.body.data;
res.send(' Done ');
});
// PHP Side
httpPost('NODE_URL:2200/get_php_data', array('data' => 'some data'));
function httpPost($url,$params)
{
$postData = http_build_query($params);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
<?php exec('node receiver.js')