[php-src] Issue #7990: Build only php -S, passthru(), redirect to server from symlink
| From: | KapitanOczywisty | Date: | Sat, 22 Jan 2022 18:04:58 +0000 |
| Subject: | [php-src] Issue #7990: Build only php -S, passthru(), redirect to server from symlink | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239228@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7990
Comment Author: KapitanOczywisty
PHP is not good for such tasks, but since you know something about JS you should use NodeJS.
This is proof-of concept, but it's place to start:
```js
const http = require("http");
const { spawn } = require("child_process");
/** @type {http.RequestListener} */
const requestListener = function (req, res) {
console.log("client connected");
res.setHeader("Vary", "Origin");
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET");
res.setHeader("Content-Type", "application/octet-stream");
res.writeHead(200);
const cmd = spawn("parec", ["-d", "@DEFAULT_MONITOR@"]);
cmd.stdout.on("data", (chunk) => {
console.log("cmd data " + chunk.length);
res.write(chunk);
});
req.on("close", () => {
console.log("client end");
cmd.kill();
});
cmd.on("close", () => {
console.log("cmd end");
res.end();
});
};
const server = http.createServer(requestListener);
server.listen(8080);
```
And run with:
```bash
node ./index.js
```
https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
https://nodejs.org/api/http.html#httpcreateserveroptions-requestlistener