Comments (8)
I got PHP.wasm working in the local worker
dev env provided by CloudFlare, I shared the setup below.
The bad news: I couldn't deploy it because of the 5MB size limitation β php_8_0.wasm
is around 5.8MB. Maybe there's a way to get under 5MB π€ I'm rebuilding PHP with no extensions and more aggressive optimizations to find out.
Edit: I got it down to 4.4MB!
src/index.js:
import { PHP } from './web/index-213897b2.js';
import wasm from './web/php_7_3.wasm';
const phpPromise = PHP.load('7.3', {
emscriptenOptions: {
instantiateWasm(info, receive) {
phpError = JSON.stringify(Object.keys(info.a));
let instance;
try {
instance = new WebAssembly.Instance(wasm, info)
} catch (e) {
phpError = e + 'thrown!';
throw e;
}
phpError = instance+'';
receive(instance)
return instance.exports
},
}
}).then(loaded => {
phpError = 'loaded in theory';
php = loaded;
}).catch(e => {
phpError = e;
});
let php;
let phpError;
export default {
async fetch() {
if (php) {
const r = await php.run({
code: `<?php echo "Hello World from PHP!"; ?>`
})
return new Response(
r.text
);
} else {
return new Response(
phpError+'',
{
status: 500
}
);
}
}
}
wrangler.toml:
name = "playground-worker"
main = "src/index.js"
node_compat = true
compatibility_date = "2020-04-04"
src/web/php_7_3.js:
export const dependenciesTotalSize = 4428017;
-import dependencyFilename from './php_7_3.wasm';
+const dependencyFilename = './php_7_3.wasm';
from wordpress-playground.
Running WordPress on CloudFlare is not viable yet. Loading PHP alone exceeds CloudFlare 128MB memory limit by a tiny margin, and that doesn't even include loading WordPress files.
This issue is blocked until either PHP.wasm can run with much less memory or CloudFlare doubles the memory limit.
Longer version below:
I managed to deploy PHP into CloudFlare and now am running into this error when the worker was starting:
Error: Script startup exceeded memory limits. [code: 10021]
Then I've built PHP with a different set of options and the worker started, but the first request resulted in this error:
RangeError: WebAssembly.Instance(): Out of memory: Cannot allocate Wasm memory for new instance
CloudFlare platform limits for paid users are, as of today:
- 5MB for worker files
- 128MB memory
Measuring the memory required by the node.js build tells me it requires roughly 132MB β very narrow margin:
/usr/bin/time -l npx @php-wasm/cli -r 'echo "Hello, world";'
139237696 peak memory footprint
I've tried building PHP with the following options:
-s INITIAL_MEMORY=128MB \
-s ALLOW_MEMORY_GROWTH=0 \
But that didn't help.
from wordpress-playground.
Here's a bit more info:
; /usr/bin/time -l wrangler dev --experimental-local
(...)
15798208 peak memory footprint
According to time
, the web build running in a worker seems to peak around 15MB, far from the 128MB required for the node.js-based CLI.
However, maybe it's somehow off by one digit. Mac process monitor says 154.8 MB
of real memory consumption.
from wordpress-playground.
+1, I'd love this to happen!
from wordpress-playground.
Seems the max size for a worker is now 10MB, so that bitβs solved. Memory limit still seems to be 128MB though.
from wordpress-playground.
lowercase-f-dangit
π
from wordpress-playground.
https://github.com/cloudflare/php-worker-hello-world
from wordpress-playground.
This project uses babel-preset-php to convert PHP to JavaScript.
Nice!
from wordpress-playground.
Related Issues (20)
- Integrate wp-cli directly on playground.wordpress.net HOT 1
- Support SQLite at the network connection level
- Loggers: Silence irrelevant error logs in unit tests
- The activatePlugin step doesn't throw an error when given invalid inputs
- Playground could not serve the request.
- Improve log modal HOT 2
- How to disable the v2 wordpress-importer HOT 6
- Expired GH artifact makes install via plugin-proxy.php seem broken HOT 3
- Static files run as PHP when path includes directory like `<some-dir>.php/` HOT 10
- Unexpected error when exporting to Github HOT 14
- Remove "Step" word after each step heading
- runPHPWithOptions step in the example doesn't match with the heading HOT 2
- wpCLI step in the example doesn't match with the heading
- GitHub integration: AI descriptions for Pull Requests
- PHP: Support libwebp on PHP 7.0 β 7.3 HOT 6
- Playground embeds WordPress site within iframe without including the allow-top-navigation HTML attribute HOT 4
- Synchronous XHR request not supported, always yielding a 404 error HOT 13
- Secure client-side storage on playground.wordpress.net to avoid going through the GitHub connection flow so often HOT 4
- GitHub integration: Pull upstream to fork before creating a PR
- Load indicator for redirects HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-playground.