FrankenWasm - WebAssembly plugins #2271
johanjanssens
started this conversation in
Show and tell
Replies: 3 comments 4 replies
-
|
Awesome work! Would you mind opening a PR to expose the fun in you need? We'll be glad to merge it. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Now this one is even more fun than the last one! I think you've more than proven how useful directly reaching out to php threads can be, so we really should merge in the changes. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
how would this compare to using Extism's php sdk? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I gave a talk at ConFoo Montreal last week about building PHP extensions with WebAssembly. The idea: write plugins in Rust, Go, or JavaScript, compile to
.wasm, and call them from PHP through a simple class, no C, no FFI, no shelling out.The approach: a
FrankenPHP\WasmPHP class backed by a C extension that bridges PHP → Go → Extism → Wazero. Plugins are sandboxed.wasmfiles discovered at startup. Each HTTP request gets its own plugin instances, fully thread-safe.PHP data in, PHP data out, arguments are automatically JSON-encoded, and if the plugin returns JSON it's decoded back to PHP arrays/values. Anything you can
json_encode()works as input.The repo has 20 plugins across three languages, from a 256 KB ASCII art generator in Rust to a 7 MB React JSX server-side renderer in JavaScript. A few highlights:
Writing a plugin is minimal, here's a complete Rust HTML sanitizer:
Compile, drop the
.wasmin the plugins directory, done. Same pattern for Go and JS with their respective Extism PDKs.Like FrankenAsync, this requires the same little fork that adds
frankenphp.Thread(index)andfrankenphp_thread_index()to reach the request context from a C extension. Everything else uses upstream FrankenPHP, includingRegisterExtension.Beta Was this translation helpful? Give feedback.
All reactions