• Stars
    star
    399
  • Rank 104,370 (Top 3 %)
  • Language
    JavaScript
  • License
    BSD 2-Clause "Sim...
  • Created about 13 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node.js interfacing with PHP-FPM through FastCGI

Inline PHP Server Running on Node.js

Be worried, be very worried. The name NodePHP takes its name from the fact that we are effectively turning a nice Node.js server into a FastCGI interface that interacts with PHP-FPM.

This is omega-alpha-super-beta-proof-of-concept but it already runs a few simple scripts. Mostly done for my talks on Node.js for PHP Developers this turns out to be quite an interesting project that we are most likely be going to use with Orchestra when we decide to release our Inline PHP server that allows people to run PHP without Apache, Nginx or any webserver.

Yes this goes against all ideas and concepts of Node.js but the idea is to be able to create a web-server directly from any working directory to allow developers to get going even faster than it was before. No need to create vhosts or server blocks ore modify your /etc/hosts anymore.

Synopsis

This node.js module is made for the sole purpose of my conference talk but also to allow developers to get started with PHP even faster than the usual. After installing this node-module, developers need to make sure they have PHP-FPM running somewhere on their system. If it is, they will be able to go to any of their web-directory (that the FPM user has access to) and simply type node php and from there they will see a nice little output that looks like this:

bash$~ PHP Server is now running on port 9001
       Incoming Request: GET /test.php
         --> Request Response Status Code: "200"

This is going to be running in the browser allowing you to develop and test your applications faster. Hopefully you will end up forking the project and helping out because I do not have enough time to do all I would want to do with this thing.

What?

It allows you to go into a directory, type "node-php" and have a running webserver that serves PHP. Happy?...

Installing

Well this is a bit tricky, there are a few things you will need in order to get this thang running:

  • You need a running PHP-FPM server.
  • You need to have Node.js installed with NPM
  • Install node-fastcgi-parser ( https://github.com/billywhizz/node-fastcgi-parser )
  • Then you git clone git://github.com/davidcoallier/node-php.git, then you git submodule init, then you git submodule update, and npm install

For this beta version, we assume that you are running FPM off localhost on port 9000. If you are running through a socket you may want to make your own script that looks like this:

var php = require('nodephp');
php.nodephp({
    fcgi: {
        port: '/tmp/php-fpm.sock',
        host: null,
    },
    server: {
        port: 9998
    }
});

Please note that the sock connection has not been tested yet. All that has been tested is connecting to a different FastCGI port and starting the server on a different port like such:

var php = require('nodephp');
php.nodephp({
    fcgi: {
        port: 9001,
        host: 'localhost',
    },
    server: {
        port: 9111
    }
});

Serving Static Files

You will realise rapidly enough that only running this is quite useless as it does not serve static files and such. This is why the node-php code has the abiliyt to define blocks — albeit simple blocks. They are defined in the second argument of the nodephp call:

var php = require('nodephp');
php.nodephp({
    fcgi: {
        port: 9001,
        host: 'localhost',
    },
    server: {
        port: 9111
    }
}, {
    "\.(js|css|png|jpg|jpeg|gif|txt|less)$": php.NODEPHP_TYPE_STATIC,
    "\.php$": php.NODEPHP_TYPE_FCGI,
    "index": "index.php"
});

Where the following are:

NODEPHP_TYPE_STATIC: Static files that do not need to go through the fastcgi handler (`fastcgi_pass`)
NODEPHP_TYPE_FCGI: Files you do send through the FCGI handler.

If you want more simple using the default localhost:9000 for the FCGI handler:

var php = require('nodephp');
php.nodephp({}, {
    "\.(js|css|png|jpg|jpeg|gif|txt|less)$": php.NODEPHP_TYPE_STATIC,
    "\.php$": php.NODEPHP_TYPE_FCGI,
    "index": "index.php"
});

Hopefully this helps.

Issues & Todos

There are a few very important issues right now:

  • There is no POST handling. I'm not that far in the FCGI specs yet — need to find how to send data (post data)
  • There is no base url. If you include ../../../../poop it will try to load it and most likely will fail.
  • If you try to load a file that the PHP-FPM worker does not have access to, it will fail silently and you will swear. A lot. By silently I mean, it will give you a 404 even though the files do exist.

Disclaimer

This is an ugly prototype and if you run this in production you are most likely mentally challenged (Not that it's a bad thing..) but I take no responsibility for what you do with this. Moreover, this goes against everything Node.js stands for. So realise that.

License

Released under the New BSD License.

Copyright (c) 2011 David Coallier

More Repositories

1

node-graph

A Graph Theory module for node.js
JavaScript
41
star
2

node-simplewhois

A simple node.js whois module.
JavaScript
29
star
3

Google-Wave-PHP

This is a PHP 5.3 Developers Library for Google Wave
PHP
28
star
4

Services_Capsule

PHP Interface to the Capsule CRM web service.
PHP
27
star
5

frapi-oauth2

A OAuth2 Access-Token helper for FRAPI developers
PHP
13
star
6

include-html

A jQuery plugin to include remote html within a custom html <include> tag
JavaScript
9
star
7

jsconfeu-2011

JSConfEU technology mixes talk
JavaScript
7
star
8

SPL_Types

SPL Types
C
6
star
9

frapi-logger

Log incoming FRAPI requests in a way that's non-obstrusive
PHP
6
star
10

pear-reviews

A set of PEPr reviews to help new PEAR developers
4
star
11

MathematicsGameTheory

A list of games in Game Theory
4
star
12

stripe-php

Stripe PHP bindings
PHP
3
star
13

jquery-konami

This is yet another konami jquery plugin but this one also has a textual mapping of keys.
JavaScript
3
star
14

yafyaf

This is a VERY VERY simple framework to create simple websites. Configurations are stored in simple xml files ability to add menus, remove menus, submenus, etc.
PHP
2
star
15

node-restlike

A node.js "REST-like" server. Not pretentious enough to be RESTful.
JavaScript
2
star
16

SPL-Autoload-PSR

The Autoload PSR php function
C
2
star
17

html5valentine.com

html5 valentine
JavaScript
2
star
18

services_url

Services URL for Short URLs
PHP
2
star
19

howto

Example Orchestra Application
PHP
1
star
20

sample-symfony

A sample Symfony project example
PHP
1
star
21

OSI-Days-Workshop

This is a portfolio management API
PHP
1
star
22

thrift

This is a mirror of The Unofficial Thrift Git Repository
C++
1
star
23

git-summit

The Virtual Git Summit
1
star
24

r-bloggers-sideless

A Google Chrome extension to read R-Bloggers without the sidebars.
JavaScript
1
star
25

jquery-battery

A jQuery Plugin for interfacing with the Battery API.
JavaScript
1
star
26

HTTP_XAuth

An XAuth helper
1
star
27

Math-Ref-Extras

Happy Maau Math Ref Extras
1
star
28

Zen

The network behind CoderDojo
PHP
1
star
29

nginx-spdy

This is a Github version of the nginx-spdy patches from http://nginx.org/patches/spdy/
1
star
30

Feed_OData

This is the initial PEAR package for the OData PHP Library
PHP
1
star
31

davidcoallier.github.com

page with projects linked to
1
star
32

Services_Amazon_s3

http://pear.php.net/Services_Amazon_S3
PHP
1
star
33

github-upstream-button

Adds a GitHub upstream "button" on forked repositories
JavaScript
1
star
34

hackforgood

The website for HackForGood
1
star
35

rubies-learning

My random tests with various rubies :)
Ruby
1
star
36

sample-lithium

sample-lithium
PHP
1
star