kambo / webassembly
Run web assembly in PHP
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:C
Requires
- php: ^8.1
Requires (Dev)
This package is auto-updated.
Last update: 2025-01-11 20:55:24 UTC
README
An quick POC (done in ~3 hours) for running WebAssembly modules using Wasmer.
Installation
You can install the package via composer:
composer require kambo/webassembly
Usage
Please see the examples directory for usage examples.
$engine = new Kambo\WebAssembly\Engine(); $store = new Kambo\WebAssembly\Store($engine); // Example WAT (WebAssembly Text) code $wat = '(module (func $sum (param i32 i32) (result i32) local.get 0 local.get 1 i32.add) (export "sum" (func $sum)))'; $wasmBytes = WasmerFFI::watToWasm($wat); $module = new Module($store, $wasmBytes); $instance = new Instance($store, $module); $args = Collection::from([10, 32], Value::KIND_I32); $result = $instance->callFunction('sum', $args); echo $result[0]->asI32(); // Outputs: 42
Current limitations
- ๐ง Needs FFI extension to be enabled.
- โ ๏ธ Just a POC, can segfault at any moment.
- ๐งน It's probably leaking memory.
- ๐ฆ Wasmer runtime is bundled with the library - not a good idea for production.
- โก Limited support for some WebAssembly features.
- ๐ Does not support Mac OS (I forget password to my Mac ).
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.