Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand Down
110 changes: 55 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.
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
Expand All @@ -21,9 +21,9 @@ sure they have PHP-FPM running somewhere on their system. If it is, they will be
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"
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
Expand All @@ -39,84 +39,84 @@ 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`
- 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
}
});
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
}
});
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"
});
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.
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"
});
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.

- 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
Expand Down
10 changes: 5 additions & 5 deletions lib/cli-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

var path = require("path"),
args = process.argv.slice(1)
args = process.argv.slice(1)

var arg, base;
do arg = args.shift();
while ( arg !== __filename &&
(base = path.basename(arg)) !== "node-php" &&
base !== "php" &&
base !== "php.js"
while ( arg !== __filename &&
(base = path.basename(arg)) !== "node-php" &&
base !== "php" &&
base !== "php.js"
)

require("./php").run(args)
Loading