Package Exports
- node-phpcgi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-phpcgi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-phpcgi
Execute php in node with php-cgi.
Foreword
Before using this, make sure you have already installed the php-cgi
Note:Not the php command.
Quick Start
First, install it in your project directory:
npm install node-phpcgiThen, use it in your node server like this:
var middleware = require('node-phpcgi')({
documentRoot: __dirname,
// change it to your own handler path
handler: '/usr/local/php/bin/php-cgi'
});
var app = http.createServer(function(req, res) {
middleware(req, res, function(err, result) {
// result: {statusCode: 200, headers: {content-type: 'text/html'}, body: 'html'}
});
});Specially, for edp, in the edp-webserver-config.js:
// ...
var phpcgi = require('node-phpcgi')({
documentRoot: __dirname,
// change it to your own handler path
// note: double backslash char `\\` in windows style path
// windows: "C:\\Program Files\\PHP\\php-cgi.exe"
handler: '/usr/local/php/bin/php-cgi'
});
// ...
exports.getLocations = {
return [
// ...
{
location: /\.php($|\?)/,
handler: [
function(context) {
context.stop();
phpcgi(context.req, context.res, function(err, result) {
context.status = result.statusCode;
context.headers = result.headers;
context.content = result.body;
context.start();
});
}
]
}
// ...
];
};Test
Before test
Before you can run the tests, you should change the handler path in the test/spec.js file:
var middleware = phpcgi({
documentRoot: __dirname + '/htdocs',
// change it to your own path
handler: '/usr/local/php2/bin/php-cgi'
});After change the handler path to you own, you can do this:
npm install -g mocha
# cd the repo directory
npm install supertest
mochaThis package is inspired from gateway.