-
Notifications
You must be signed in to change notification settings - Fork 322
Description
I recently explored the deployment of a headless WordPress app without a traditional PHP server, using WP Playground. This exploration is documented in the blog post Deploying a Headless WordPress App Without a PHP Server: WP Playground Use Case
In my exploration to deploy a Headless WordPress App (NextJs App + WordPress<>PHP runtime) directly into a free NodeJS hosting without the need of a specific PHP server (PHP/WordPress code runs directly in Node via Playground packages) I faced three major challenges:
- Port Conflicts
- High Memory Requirements
- Large Bundle Size
Port Conflicts
Playground CLI spins up its own web server, as does frameworks like Next.js.
Vercel, however, only allows one server process to expose a public port.
I worked around this one by calling the requestHandler.request()
function directly instead of running another server.
Note
This led me to creation and release of the the wordpress-playground-handler
NPM package. that encapsulates the WordPress instance creation using the Node version of Playground—without relying on an Express server.
High Memory Requirements
When checked the use of memory for my NextJS APP using an internal Playground instance I got the following metrics
-----------------------------
Memory usage at 7/1/2025, 9:17:03 AM:
rss: 864.63 MB - Resident Set Size: total memory allocated for the process (includes all C++ and JS objects, stacks, etc.)
heapTotal: 102.56 MB - V8's total heap size
heapUsed: 96.56 MB - V8's used heap size
external: 2469.72 MB - Memory used by C++ objects bound to JS objects managed by V8
arrayBuffers: 445.47 MB - Memory allocated for ArrayBuffers and SharedArrayBuffers
-----------------------------
My read of these metrics is that at this snapshot in time, the process used about 865 MB of resident memory, but it also had over 2.4 GB in external memory allocations, so total memory needs could easily exceed 3 GB depending on runtime behavior.
In terms of RAM, Vercel's Serverless functions offer 2GB'S of RAM for their free plan
render.com has a limit of 512Mb of RAM in their free plan.
According to @adamziel's assessment in another conversation:
We should be able to reduce memory usage to the 20–100 MB range, if that's worthwhile.
Achieving this would resolve the RAM issues. Anything below 512Mb of RAM should be enough to make Playground viable for lightweight use cases.
Large Bundle Size
Playground in Node depends on WASM packages that produce more than 500 MB of bundle size, which exceeds the limits of many serverless hosting platforms. Getting the final bundle to be something below 250Mb should make Playground viable for lightweight use cases.
This is @adamziel's assessment from another conversation:
That’s because we distribute all the PHP releases as a single npm package (@php-wasm/node and @php-wasm/web). It would be much smaller if we distributed a single package per PHP version, e.g. @php-wasm/node-7-4, @php-wasm/node-8-0 etc. There are no technical blockers to that, it’s just a matter of prioritization.
Tasks
As a conclusion, the following issues need to be solved to get Playground to properly work in Node for lightweight use cases: