Skip to content

Instantly share code, notes, and snippets.

@falsecz
Created January 25, 2012 09:18
Show Gist options
  • Save falsecz/1675582 to your computer and use it in GitHub Desktop.
Save falsecz/1675582 to your computer and use it in GitHub Desktop.
Node.JS php exec
// /usr/local/src/httpd-2.3.16-beta/support/ab -r -n 10000 -c 10 http://127.0.0.1:1327/
var http = require('http');
var sys = require('util')
var exec = require('child_process').exec;
var util = require('util');
var cnt = 0;
http.createServer(function (req, res) {
if(cnt++ % 1000 == 0) {
util.log('requests: ' + cnt);
util.log(util.inspect(process.memoryUsage()));
}
child = exec("php -r 'echo \"{php_time: \" . microtime(true) . \"}\";'", function (error, stdout, stderr) {
if (error !== null) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
var r = {
code: 500,
message: stdout + stderr
};
res.write(JSON.stringify(r));
}
else {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.write(stdout);
}
res.end();
}
);
}).listen(1327, "127.0.0.1");
util.log('Server running at http://127.0.0.1:1327/');
util.log(util.inspect(process.memoryUsage()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment