JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q54777F
  • License BSD-2-Clause

Execute php in node with php-cgi

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.

quick start

First, install it in your project directory:

npm install node-phpcgi

then, use it in your node server like this:

var middleware = require('node-phpcgi')({
    documentRoot: './htdocs',
    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: './',
    handler: '/usr/local/php/bin/php'
});
// ...
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

npm install -g mocha

# cd the repo directory
mocha

This repo is inspired from gateway.