fnobi / php-express Goto Github PK
View Code? Open in Web Editor NEWenable express server to exec php.
enable express server to exec php.
Large response sizes from php scripts trigger maxBuffer error:
Error: stdout maxBuffer exceeded.
at Socket.<anonymous> (child_process.js:792:12)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at Pipe.onread (net.js:538:20)
This can be resolved by inserting a maxbuffer increase in engine.js. line 39, e.g.:
child_process.exec(command, {maxBuffer: 1024 * 15000}, function (error, stdout, stderr)
Not sure how best to pass in such an argument when configuring php-express - would be preferable to editing source for each installation.
I'm using php-express to serve PHP pages that occasionally return content other than text/html. In particular, I have a page which returns JSON, and has a header("Content-type: application/json") statement. However, the headers returned from this request are still text/html, as verified by the network monitor in FireFox, and the fact that prototype.js (which I'm using in the code which reads this response) does not set responseJSON in the Ajax response.
I've gotten around this problem by using prototype.js's evalJSON() function, but this fails to address the issue.
I have php code that depends on the value of the current location using $_SERVER['PHP_SELF'] but it looks like no matter what page I'm on that value is set to this:
[PHP_SELF] => server/node_modules/php-express/lib/PHPExpress/../../page_runner.php
Is there a way to have the $_SERVER values set to reflect the requested url?
Also the $_SERVER['REQUEST_URI'] value is not set at all (otherwise I could use that instead).
I can get my server running, I even copied the basic app.js from the readme, and it still says "Error: Command failed: 'export' is not recognized as an internal or external command,
operable program or batch file".
I'm on windows.
Am I doing something wrong? Do I have to set an env variable?
child_process.exec(command,{
env: env,
maxBuffer: 8 * 1024 * 1024
},
...
lib/PHPExpress/engine.js 第32到34行,没有设置maxBuffer导致缓冲区大小只有默认的200k,当页面大小超出200k页面就会被截断,建议添加maxBuffer参数,如上
your module can be used with template engines?
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/views');
app.set('view engine', 'html');
Error: Command failed: php ...................... php-express/lib/PHPExpress/../../page_runner.php /home/runner/Express-Server/views .............................. /views/index.php
/bin/sh: 1: php: not found
at ChildProcess.exithandler (child_process.js:308:12)
at ChildProcess.emit (events.js:314:20)
at ChildProcess.EventEmitter.emit (domain.js:483:12)
at maybeClose (internal/child_process.js:1022:16)
at Socket.<anonymous> (internal/child_process.js:444:11)
at Socket.emit (events.js:314:20)
at Socket.EventEmitter.emit (domain.js:483:12)
at Pipe.<anonymous> (net.js:675:12)
I spent quite some time to get it to work.
For who is wondering how to do it
return res.render("index.php", {
get: {
slug: slug
}
});
same thing for a POST request
I have a local server and script and was working fine before, but now it hangs when I use any shell_exec function (even to just log or write something for test). Is this new? It has been working for years before.
Do I need to set anything to allow it?
basically i copy pasted you example and changed the directories, but when i request the page i get a download
php is the path
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const submission = require('./models/submission');
const cors = require('cors');
const app = express();
var phpExpress = require('php-express')({
// assumes php is in your PATH
binPath: 'php'
});
app.set('views', path.join(__dirname, 'end-user/dist'));
app.engine('php', phpExpress.engine);
app.set('view engine', 'php');
// routing all .php file to php-express
app.all(/.+\.php$/, phpExpress.router);
// Parsers for POST data
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: false, limit: '10mb' }));
// Point static path to dist
app.use(express.static(path.join(__dirname, 'end-user/dist')));
app.get('*', (req, res) => {
console.log('HAllo?!');
res.sendFile(path.join(__dirname, '/end-user/dist/index.php'));
});
console.log(__dirname);
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '16484';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));
I tried making a simple form that prints the $_POST array on submission:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
if(isset($_POST['uname'])) {
print_r($_POST);
}
?>
<form action='http://example.com/current_page.php' method='post'>
Username:<br>
<input type='text' name='uname'><br>
Password:<br>
<input type='password' name='pword'><br><br>
<input type='submit' value='Submit'>
</form>
</body>
</html>
It never sends off the data. Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.