http-node-phpfpm
node.js run php scripts via phpfpm
npm install http-node-phpfpm
Usage
var PHPFPM = ; var phpfpm = host: '127.0.0.1' port: 9000 documentRoot: __dirname; phpfpm;
Configuration
var phpfpm = configObject;
configObject may have the following keys:
documentRoot
optional [string] the document root folder of PHP scripts. must ends with /host
optional [string] the ip or host name of php-fpm server (default: 127.0.0.1)port
optional [int] the port of php-fpm server ( default: 9000 )sockFile
optional [string] use the unix sock file instead of 127.0.0.1:9000 to connect php-fpm server
APIs
run(options, callback)
available keys in options object
uri
[string] path to your phpfileurl
[string] alias of urimethod
optional [string] GET or POST (default: GET)form
optional [object] form_data that will be send with content-type: application/x-www-form-urlencodedjson
optional [object] json data that will be send with content-type: application/jsonbody
optional [string] raw post body datacontentType
optional [string] the content-type headercontentLength
optional [string] the content-length header
if you send a string as options
, it will be converted to:
uri: "the string value" method: 'GET'
callback
{ // if err === 99, means php-fpm error // it may be lost php-fpm connection or too many connections // otherwise it will always equal to false // output is the stdout of php scripts // phpErrors is the php errors detail string // php will output some errors, but that does not mean the request fails // if you turn on display_errors in your php.ini, the phpErrors content will also be found in the output string console; }
Demo
Simple php request with no parameters
phpfpm;
Send data via GET method
phpfpm;
Send form data via POST method
phpfpm;
Send json data with POST method
phpfpm;
Send form data with GET method
phpfpm;
Send form data and query string with GET method
phpfpm;
Send raw body data with POST method
phpfpm;
License
MIT
Thanks
This project is based on the great work of node-phpfpm
written by longbill. longbill/node-phpfpm and node-fastcgi-client
written by LastLeaf. LastLeaf/node-fastcgi-client