Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Question - Does the playground need to be stopped? #5

Open
jonathanbossenger opened this issue Apr 4, 2023 · 2 comments
Open

Question - Does the playground need to be stopped? #5

jonathanbossenger opened this issue Apr 4, 2023 · 2 comments

Comments

@jonathanbossenger
Copy link

(Note, I know that this repo is going to be moved eventually, so I'm just logging questions I have about how it works. Happy to wait till the repo is moved for the answers).

After the last update the playground opens in a browser tab (great update), but it makes me wonder, do I need to somehow stop the playground. I assume it uses some resources to launch, so how could I stop it once I don't need it anymore? Or would the same playground be used if I launched it from a different plugin?

@danielbachhuber
Copy link
Owner

but it makes me wonder, do I need to somehow stop the playground. I assume it uses some resources to launch, so how could I stop it once I don't need it anymore?

That's a great question!

It launches a server when you run the 'Launch WordPress Playground' command:

const server = http.createServer( async (req : any, res : any) => {
let requestHeaders: { [ key: string ]: string } = {};
if ( req.rawHeaders && req.rawHeaders.length ) {
for ( let i = 0; i < req.rawHeaders.length; i += 2 ) {
requestHeaders[ req.rawHeaders[ i ] ] = req.rawHeaders[ i + 1 ];
}
}
const params = url.parse(req.url, true).query;
const phpVersion = params.php;
// console.log( "PHP",phpVersion, req.url, params );
if (phpVersion) {
phpBrowser = await loadPhpBrowser( context, openPort, pluginPath, phpVersion);
}
const reqBody = await new Promise( (resolve, reject) => {
let body = '';
req.on('data', (chunk: any) => {
body += chunk.toString(); // convert Buffer to string
});
req.on('end', () => {
resolve(body);
});
}) as string;
const resp = await phpBrowser.request( {
relativeUrl: req.url,
headers: requestHeaders,
method: req.method,
body: reqBody,
} );
res.statusCode = resp.httpStatusCode;
Object.keys(resp.headers).forEach((key) => {
res.setHeader(key, resp.headers[key]);
});
res.end(resp.body);
});

I'm not sure how the server is shut down...

Or would the same playground be used if I launched it from a different plugin?

We launch a new server for each invocation of 'Launch WordPress Playground'.


@adamziel My WordPress Playground is somehow stuck on v0.0.2:

image

I saw you published v0.0.8 in the last few days. I tried uninstalling and re-installing but it didn't change things. Any ideas what the cause might be?

@adamziel
Copy link
Collaborator

At the moment, there's no way to stop a server once you start it. It would be great to have some UI for this and also for switching WP and PHP versions. Version 0.0.9 perhaps? :-)

@danielbachhuber this is super weird! I suspect it's somehow linked to the fact you've developed v0.0.2 on your computer. Perhaps you've copied the extension file manually somewhere? Regardless, are you able to install v0.0.8 via the "Install Another Version..." option here?

CleanShot 2023-04-12 at 11 37 45@2x

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants