Execute PHP Scripts Within Node.Js Web Server

Execute PHP scripts within Node.js web server

Node.js only supports JavaScript. Here is a tutorial on how to have PHP running with Node.js on the side.

http://blog.mixu.net/2011/01/04/nginx-php-fpm-and-node-js-install-on-centos-5-5/

PHP execute nodejs from another server

Many ways to deal with it. Most easiest and straightforward way would be to setup a server on your (or the target) computer and then simply pass on the request. This will be able to control node script and php script individually.

On your PHP file you can simply use file_get_contents,

$text="some data to pass";
$homepage = file_get_contents("http://YOURPUBLICIPADDRESS:3000/?text=$text");
echo $homepage;

And on your node api, you can have some route which will handle the jsFunction from there, assuming it's a promise, I can probably use expressJS to handle it.

var express = require('express')
var jsFunction = require('./jsFunction')
var app = express()

app.get('/', function (req, res) {
jsFunction(req.query.text).then(data=>res.send({data}))
})

app.listen(3000)


Related Topics



Leave a reply



Submit