run php on node js server

var http = require("http"),
fs = require("fs"),
path = require("path"),
url = require("url"),
runner = require("child_process");

function sendError(errCode, errString, response)
{
  response.writeHead(errCode, {"Content-Type": "text/plain;charset=utf-8"});
  response.write(errString + "\n");
  response.end();
  return false;
}

function sendData(err, stdout, stderr, response)
{
  if (err) return sendError(500, stderr, response);
  response.writeHead(200,{"Content-Type": "text/plain;charset=utf-8"});
  response.write(stdout);
  response.end();
}

function runScript(exists, file, param, response)
{
  if(!exists) return sendError(404, 'File not found', response);
  runner.exec("php " + file + " " + param,
   function(err, stdout, stderr) { sendData(err, stdout, stderr, response); });
}

function php(request, response)
{
  var urlpath = url.parse(request.url).pathname;
  var param = url.parse(request.url).query;
  var localpath = path.join(process.cwd(), urlpath);
  fs.exists(localpath, function(result) { runScript(result, localpath, param, response)});
}

var server = http.createServer(php);
server.listen(1000);
console.log("PHP ready to run script given on port 1000.");

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
run php script from nodejs how run php scripts inside nodejs node js execute php how to execute php code within nodejs how to run php in node js server node run a php file can php using node js as web server nodejs run php can i run php script in node application run php in node can you run php in node.js server can you run php on node.js server node.js server run php can php run node script can node run inside php run php on node run php using nodejs How to run node js file in PHP node.js php server how to use node js script with php project how to run php file in node server node.js run php run nodejs in server php run node.js in php server run php in node js how to run php file with node js node js run php file node.js run php script can php run node js server how to run node javascript file from php nodejs server with php nodejs php execute run php on node js run php on node s is it possible to run node js in php can I run nodejs script as php? can i run php scripts on a nodejs server Can I have php scripts in a NodeJS Server? how to run a node js script in php php run node js script CAN I RUN A NODE.JS FILE FROM PHP FILE php serve node js how to run node.js file in php how to run php with node server run php file on node server Run PHP script from Node JS running node.js in php simple node js php server execute node.js from php how to run php file with nodejs run php with nodejs can you run php on node js run php command in html nodejs running php file nodejs running php nodejs how to run node.js in php how to run a php script in a node js server locally can i run php in a node server php run in node.js run node js in php can I run php using node.js how to run php website using node.js execute php in nodejs node run php execute node js from php can node js run php? can nodejs run php? can run php in node server php inside javascript node how to run php files through nodek how to run php using node js run php in node.js how to locally test php through node.js serve nodejs with php node.js run php project run php with node.js node js execute php file how to interpret php and nodejs php web server with node js execute php script by node nodejs execute php script node php server use php in node using php files with nodejs can node js and php files go together run node js from php run php file in nodejs use website php in node node js to run a php program use node to run a webserver for php nodejs doent read php file how to build nodejs php node js run php script nodejs page with port how to run php guide to installing php node js php code on nodejs server nodejs port run php in file nodejs run php in file how to run php with node run nodejs on php run php in nodejs how to run php on a node.js nodejs "php" run php with node js nodejs serve php run serve node with php how to run a php file through a node js server running php on node can express server run php files run php code in node js can you run php in node server node js http server php how to run php in node js node server run php execute php on nodejs php with node js run php node project can node server run php run php on node js server
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source