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
19 changes: 12 additions & 7 deletions lib/PHPExpress/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var engine = function (filePath, opts, callback) {
var binPath = this.binPath,
runnerPath = this.runnerPath,
displayErrors = this.displayErrors,
maxBuffer = this.maxBuffer,

method = opts.method || 'GET',
get = opts.get || {},
Expand All @@ -15,12 +16,18 @@ var engine = function (filePath, opts, callback) {
query = opts.query || querystring.stringify(get),
body = opts.body || querystring.stringify(post),

env = {
REQUEST_METHOD: method,
CONTENT_LENGTH: body.length,
QUERY_STRING: query
processOptions = {
env: {
REQUEST_METHOD: method,
CONTENT_LENGTH: body.length,
QUERY_STRING: query
}
};

if (maxBuffer) {
processOptions.maxBuffer = maxBuffer
}

var command = util.format(
'%s %s %s %s',
(body ? util.format('echo "%s" | ', body) : '') + binPath,
Expand All @@ -29,9 +36,7 @@ var engine = function (filePath, opts, callback) {
filePath
);

child_process.exec(command,{
env: env
}, function (error, stdout, stderr) {
child_process.exec(command, processOptions, function (error, stdout, stderr) {
if (error) {

// can leak server configuration
Expand Down
1 change: 1 addition & 0 deletions lib/PHPExpress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var PHPExpress = function (opts) {

this.binPath = opts.binPath || '/usr/bin/php',
this.runnerPath = opts.runnerPath || (__dirname + '/../../page_runner.php');
this.maxBuffer = opts.maxBuffer || 0;

// default to true for easier PHP debugging
this.displayErrors = typeof opts.displayErrors === 'undefined' ? true : opts.displayErrors;
Expand Down
7 changes: 5 additions & 2 deletions page_runner.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
//parse the command line into the $_GET variable
// parse the command line into the $_GET variable
if ( isset($_SERVER) && array_key_exists('QUERY_STRING', $_SERVER) ) {
parse_str($_SERVER['QUERY_STRING'], $_GET);
}

//parse the standard input into the $_POST variable
// parse the standard input into the $_POST variable
if (($_SERVER['REQUEST_METHOD'] === 'POST')
&& ($_SERVER['CONTENT_LENGTH'] > 0))
{
parse_str(fread(STDIN, $_SERVER['CONTENT_LENGTH']), $_POST);
}

// merge GET and POST into REQUEST
$_REQUEST = array_merge($_GET, $_POST);

chdir($argv[1]);
require_once $argv[2];