FrankenWasm - WebAssembly plugins #2271
Replies: 4 comments 6 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.
-
|
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.
-
|
how would this compare to using Extism's php sdk? |
Beta Was this translation helpful? Give feedback.
-
|
@johanjanssens You changed the future. This is big, seriously. And how poetic.. PHP just quietly winning in the background all of these years. All thanks to clever developers like you who have kept pushing the boundaries of a language that the popular crowd grew tired of talking about a many years ago. I’m genuinely excited about this and can’t wait to start building on it. If you're ever in the Bay Area (SF) please let me know, I'd love to buy you dinner or a drink and discuss the possibilities. |
Beta Was this translation helpful? Give feedback.
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