Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use PHPRequestHandler, rotate PHP and allow url fopen for curl
  • Loading branch information
jeroenpf committed Aug 23, 2024
commit 52ac2d05fee1aa9855e0cfb2c8dd7c83d605e89d
4 changes: 2 additions & 2 deletions vendor/wp-now/src/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function startServer(
app.use(compression({ filter: shouldCompress }));
app.use(addTrailingSlash('/wp-admin'));
const port = options.port ?? await portFinder.getOpenPort();
const { php, options: wpNowOptions } = await startWPNow(options);
const { php, options: wpNowOptions, requestHandler } = await startWPNow(options);
app.use('/', async (req, res) => {
try {
const requestHeaders = {};
Expand All @@ -64,7 +64,7 @@ export async function startServer(
method: req.method as HTTPMethod,
body: await requestBodyToBytes( req ),
};
const resp = await php.request(data);
const resp = await requestHandler.request(data);
res.statusCode = resp.httpStatusCode;
Object.keys(resp.headers).forEach((key) => {
res.setHeader(key, resp.headers[key]);
Expand Down
18 changes: 15 additions & 3 deletions vendor/wp-now/src/wp-now.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs-extra';
import { loadNodeRuntime } from '@php-wasm/node';
import { MountHandler, PHP, PHPRequestHandler, setPhpIniEntries } from '@php-wasm/universal';
import { MountHandler, PHP, PHPRequestHandler, rotatePHPRuntime, setPhpIniEntries } from '@php-wasm/universal';
import path from 'path';
import { SQLITE_FILENAME } from './constants';
import {
Expand Down Expand Up @@ -40,14 +40,16 @@ async function applyToInstances(phpInstances: PHP[], callback: Function) {

export default async function startWPNow(
options: Partial<WPNowOptions> = {}
): Promise<{ php: PHP; phpInstances: PHP[]; options: WPNowOptions }> {
): Promise<{ php: PHP; phpInstances: PHP[]; options: WPNowOptions, requestHandler: PHPRequestHandler }> {
const { documentRoot } = options;
const requestHandler = new PHPRequestHandler({
phpFactory: async ({ isPrimary }) => {
const id = await loadNodeRuntime( options.phpVersion );
const php = new PHP(id)
await setPhpIniEntries(php, {
'memory_limit': '256M'
'memory_limit': '256M',
'disable_functions': '',
'allow_url_fopen': '1'
});
return php;
},
Expand Down Expand Up @@ -133,10 +135,20 @@ export default async function startWPNow(
await activatePluginOrTheme(php, options);
}

rotatePHPRuntime({
php,
cwd: requestHandler.documentRoot,
recreateRuntime: async () => {
return await loadNodeRuntime(options.phpVersion)
},
maxRequests: 400,
});

return {
php,
phpInstances: [php],
options,
requestHandler,
};
}

Expand Down