-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build only php -S, passthru(), redirect to server from symlink #7990
Comments
I can't tell what you're doing or why you say that the extension resource is a "symbolic link" to a URL, but I doubt PHP is getting in the way of whatever it is. What do you expect the browser to do and what is the browser actually doing? |
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: 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: node ./index.js https://nodejs.org/api/child_process.html#child_processspawncommand-args-options |
Executing arbitrary shell scripts on any web page. In this case streaming live system audio output to speakers ("What-U-Hear") to the web page caller. Consider a jam-session that can be streamed to other peers and saved locally, an internet radio station where the source is the audio I am playing on Browser extensions have a
For example, GitHub serves CSP headers that prevent requesting When I can start and stop the local server using Native Messaging, for example https://github.com/guest271314/native-messaging-espeak-ng/blob/master/local_server.sh
https://github.com/guest271314/native-messaging-espeak-ng/blob/master/nativeTransferableStream.js
where here the output of
Currently I am streaming using Native Messaging, using the
Ideally I do not want to inject an PHP The one caveat that starting and stopping the server I have experienced is the delay between Practically, I don't need the remainder of PHP outside of local server functionality and
PHP works as expected for my uses cases. See above proofs. From what I gather NodeJS is expensive. I am trying to travel as light as possible. Comparatively what is the cost of that code versus index.php, above? What is the CPU usage comparing https://stackoverflow.com/a/48443161 with https://github.com/simov/native-messaging; and I started diving into PAC files https://bugs.chromium.org/p/chromium/issues/detail?id=839566#c40 after I filed this issue, which might be an additional alternative solution. I want to be able to request the |
For clarity,
is not technically correct, it is possible, just without user-defined code guest271314/SpeechSynthesisRecorder#17. The last time I checked the quality of audio output by WebRTC was sub-par compared to processing the raw PCM directly then using |
This is not a bug. This is a feature request. A very specific question about whether it is possible, or not, to build a minimal PHP with only The redirect to server from symbolic link is a secondary question. |
NodeJS is faster and lighter than php. Especially when dealing with shell and sockets. Also |
What is the basis of that claim? Empirical evidence? The last time I checked running NodeJS was around 25MB, PHP 18MB. Python Native Messaging host uses 12MB. That is why I use a Python Native Messaging host. You can run the PHP version https://stackoverflow.com/a/48443161 and the NodeJS version https://github.com/simov/native-messaging and Python version mdn/webextensions-examples#157 report the MB used per your OS's Task Manager equivalent here. That is not really germain to my inquiry.
My machine, and any user that employs the pattern is the production. I don't follow rules. If I did I would not be capturing monitor devices or keeping "Obey no rules, I'm doing me " -Talk To Me, Run The Jewels How to achieve the stated goals of this feature request? |
Okay, this is pretty easy to answer: No, this is not possible. A minimal build of PHP includes multiple extensions (core, standard, spl, date, json, hash, maybe more I'm forgetting) and I don't believe we have an interest in providing a more minimal build. We want that applications and libraries can depend on certain core functionality being available. |
@nikic And the second question? |
@nikic Did you miss the 2d question in this issue?
|
If you're talking about proxying requests, As for minimal build, I'm assuming you're already compiling php with
|
Doesn't sound like a question of PHP doing any proxying:
You can't symlink a file to a webpage, nor can you symlink a webpage to a webpage. That's just not how symlinks work. So that's not going to work. If you want to request some resource within a Chrome extension and have the browser redirect to a website then you'll have to find some Chrome extension-based mechanism to do so. PHP has nothing to do with this. |
@damianwadley It's not a web page. It is a local file. A locally unpacked extension is a local folder consisting of a manifest.json file, and/or other files. Those files are mapped to the extension URL Native Messaging approach uses less local resources than local server. However, connecting from an arbitrary web page to Native Messaging is not direct. I will probably stay with that approach. I was simply preforming due diligence in determining if a concept is possible: fetching local file (or symlink), which I can already do on any site, and redirecting the local file (or symlink) request to the php built-in local server. A modest proposal. In any event, I will continue trying to manifest what I am trying to achieve myself. Thanks. |
Yes, they may exist as local files, but what I mean is that they are not treated as local files. The security policy is a little different, but for most intents and purposes, chrome-extension resources look and act the same way as static files hosted on a website. |
@damianwadley FWIW I figured out how to achieve an appreciable part of the requirement. First I remove Second I use Native Messaging to start PHP built-in server
index.php
What I am having challenge with now is automatically terminating the local server when the request is aborted using
When I want to about the otherwise never-ending request
I have tried
and
after the
line. At terminal when the request is aborted I observe
printed. How can I catch the
or
and terminate/kill the current built-in server process? |
@guest271314 If you kill PHP after the audio is finished then you'll have to start it up manually the next time. That doesn't make sense to me. If what you want is to stop PHP from running, and therefore prevent the audio thing from working until you start up PHP again, then control that separately so there's no accidents. |
Description
I only require built-in local server
php -S localhost:8000
andpassthru()
, not the remainder of PHP.Additionally I need to make requests to the local server using a symbolic link.
Are the above two requirements possible?
The text was updated successfully, but these errors were encountered: