Giter Site home page Giter Site logo

node-php-fpm's Introduction

node-php-fpm

NPM Version Github License NPM Downloads

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install php-fpm

Examples

Using with http

const http = require('http')
const phpFpm = require('php-fpm')
const serveStatic = require('serve-static')

const php = phpFpm() // Optional: parameters for fastcgi-client
const serve = serveStatic(__dirname)

const server = http.createServer(function (req, res) {
  if (req.url.match(/\.php(\?.*)?$/)) {
    php(req, res)
  } else {
    serve(req, res)
  }
})

server.listen(8080)

Using with express

const express = require('express')
const phpFpm = require('php-fpm')

const app = express()

app.use(phpFpm())

app.listen(8080)

API

The available parameters for php-fpm are:

phpFpm(
  userOptions = {
    // Parameters for fastcgi-client
    host: '127.0.0.1',
    port: 9000,
    documentRoot: __dirname,
    skipCheckServer: true
  },
  customParams = {
    // Headers for php-fpm (automatically set)
    uri, // REQUEST_URI
    document, // DOCUMENT_URI
    query, // QUERY_STRING
    script // SCRIPT_FILENAME
  }
)

Parameters for fastcgi-client are available here.

rewrite option

There is an implementation of the rewrite module to handle routes the traditional nginx/Apache way.

const phpFpm = require('php-fpm')

// Route rewrite for Phalcon framework
const php = phpFpm({
  rewrite: [
    {
      rule: /.*/, // Default rule, can be omitted
      replace: '/index.php?_url=$0'
    }
  ]
})

License

MIT

node-php-fpm's People

Contributors

bezoerb avatar codebling avatar ivanfilhoz avatar tnayuki avatar twz123 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.