Hey there!

After numerous ideas of implementing WebSockets via apache, and after having 
just noticed certain problems with it too, I finally came to the conclusion 
that I should move my rather big project away from Apache, and use nodejs.

I just have one BIG problem so far: Headers.

When I spawn a process with PHP, I get the page I want…but it also shows the 
raw PHP headers - and if I use res.writeHead(200), the page becomes blank… Here 
is my code:

var docroot = "/Applications/MAMP/htdocs/DI";
var http = require('http');
var gateway = require('gateway');
var spawn = require("child_process").spawn;
var extname = require("path").extname;
var join = require("path").join;
var normalize = require("path").normalize;
var file_exists = require("fs").existsSync;

var app = http.createServer(function(req, res){
        res.setHeader("X-DIRunner","0.1");
        var bin = "php";
        var index = "index.php";
        var file = join(docroot, req.url);
        if(req.url == "/" || fs.statSync(file).isDirectory()) {
                file += normalize( "/"+index );
        }
        console.log("> url: "+req.url+" | ext: "+extname(req.url)+" | file: 
"+file);
        switch(extname(req.url)) {
                case "php": bin = "php"; break;
                case "njs": bin = "node";    break;
                case "sh":  bin = "bash";    break;
        }
        if(file_exists(file)) {
                res.writeHead(200);
                var php = spawn(bin, [file]);
                php.stdout.on("data",function(d){ res.write(d); });
                php.stderr.on("data",function(d){ res.write(d); });
                php.on("exit", function(code,sig){ res.end(); });
        } else {
                res.writeHead(404);
                res.end("File not found.");
        }
}).listen(8080);

Obviously, its a test code. But, I want to extend upon it more and more.
As I am using a Yii based website, it needs to fully support PHP.. So in the 
end, I need to port GET and POST, and also FILES…somehow :/

I tried to use the „gateway“ npm module. Promising, but outdated. It relies on 
using next();, but that function has been dead since a while now, and is, as 
far as I know, deprecated.

So if anybody can give me some good hint on how I can port my project to 
nodejs, please let me know.

Kind regards, Ingwie

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to