From 32dc76d1ca1fa0da74829a2598510b58cab75e85 Mon Sep 17 00:00:00 2001 From: zhouchengkho Date: Wed, 11 Jul 2018 10:35:59 -0400 Subject: [PATCH] add buffer support & $_REQUEST for php --- lib/PHPExpress/engine.js | 19 ++++++++++++------- lib/PHPExpress/index.js | 1 + page_runner.php | 7 +++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/PHPExpress/engine.js b/lib/PHPExpress/engine.js index d0846a8..279f2e4 100644 --- a/lib/PHPExpress/engine.js +++ b/lib/PHPExpress/engine.js @@ -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 || {}, @@ -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, @@ -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 diff --git a/lib/PHPExpress/index.js b/lib/PHPExpress/index.js index a6bf23b..98933a6 100644 --- a/lib/PHPExpress/index.js +++ b/lib/PHPExpress/index.js @@ -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; diff --git a/page_runner.php b/page_runner.php index 1568c0c..affbb30 100644 --- a/page_runner.php +++ b/page_runner.php @@ -1,15 +1,18 @@ 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];