https://github.com/wasmerio/wasmer-php
ππΈοΈ WebAssembly runtime for PHP
https://github.com/wasmerio/wasmer-php
php php-extension rust wasm wasmer webassembly
Last synced: 7 months ago
JSON representation
ππΈοΈ WebAssembly runtime for PHP
- Host: GitHub
- URL: https://github.com/wasmerio/wasmer-php
- Owner: wasmerio
- License: mit
- Created: 2018-11-16T14:11:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T08:32:43.000Z (almost 2 years ago)
- Last Synced: 2025-06-22T06:15:24.772Z (7 months ago)
- Topics: php, php-extension, rust, wasm, wasmer, webassembly
- Language: PHP
- Homepage: https://wasmerio.github.io/wasmer-php/wasm/
- Size: 24.5 MB
- Stars: 1,041
- Watchers: 37
- Forks: 43
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
A complete and mature WebAssembly runtime for PHP based on [Wasmer].
[Wasmer]: https://github.com/wasmerio/wasmer
# Features
* **Easy to use**: The `wasmer` API mimics the standard WebAssembly C API,
* **Fast**: `wasmer` executes the WebAssembly modules as fast as possible, close to **native speed**,
* **Safe**: All calls to WebAssembly will be fast, but more importantly, completely safe and sandboxed.
# Install
To install the library, follow the classical:
```bash
git clone https://github.com/wasmerio/wasmer-php
cd wasmer-php/ext
phpize
./configure --enable-wasmer
make
make test
make install
```
> Note: Wasmer doesn't work on Windows yet.
# Examples
Procedural API
```php
Hello World!' . PHP_EOL;
return null;
}
$functype = wasm_functype_new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType());
$func = wasm_func_new($store, $functype, 'hello_callback');
wasm_functype_delete($functype);
$extern = wasm_func_as_extern($func);
$externs = new Wasm\Vec\Extern([$extern]);
$instance = wasm_instance_new($store, $module, $externs);
wasm_func_delete($func);
$exports = wasm_instance_exports($instance);
$run = wasm_extern_as_func($exports[0]);
wasm_module_delete($module);
wasm_instance_delete($instance);
$results = wasm_func_call($run, new Wasm\Vec\Val());
wasm_store_delete($store);
wasm_engine_delete($engine);
```
Object-oriented API
```php
Hello World!'.PHP_EOL;
return null;
}
$functype = Wasm\Functype::new(new Wasm\Vec\ValType(), new Wasm\Vec\ValType());
$func = Wasm\Module\Func::new($store, $functype, 'hello_callback');
$extern = $func->asExtern();
$externs = new Wasm\Vec\Extern([$extern->inner()]);
$instance = Wasm\Module\Instance::new($store, $module, $externs);
$exports = $instance->exports();
$run = $exports[0]->asFunc();
$args = new Wasm\Vec\Val();
$results = $run($args);
```
This example covers the most basic Wasm use case: we take a Wasm module (in its text representation form), create
an instance from it, get an exported function and run it.
You can go through more advanced examples in the dedicated directories:
* [Procedural API]
* [Object-oriented API]
[Object-oriented API]: examples
[Procedural API]: ext/examples
# Supported platforms and features
## Platforms
| Platform | Architecture | Status |
|----------|--------------|:------:|
| Linux | `amd64` | β
|
| Linux | `aarch64` | β |
| Windows | `amd64` | β |
| Darwin | `amd64` | β
|
| Darwin | `aarch64` | β |
| PHP | Status |
|-----|:------:|
| 8.0 | β
|
| 7.4 | β |
| 7.3 | β |
## Features
## Compilers and engines
| Compiler | Status |
|------------|:------:|
| Cranelift | β
|
| LLVM | β |
| Singlepass | β |
| Engine | Status |
|-------------|:------:|
| Native | β
|
| JIT | β
|
| Object File | β |
## Runtime
| Object | Status |
|-------------|:------:|
| config | β
|
| engine | β
|
| store | β
|
## Types
| Type | Status |
|------------|:------:|
| valtype | β
|
| functype | β
|
| globaltype | β
|
| tabletype | β
|
| memorytype | β
|
| externtype | β
|
| importtype | β
|
| exporttype | β
|
## Objects
| Object | Status |
|----------|:------:|
| val | β
|
| frame | β
|
| trap | β
|
| foreign | β
|
| module | β
|
| func | β
|
| global | β
|
| table | π§βπ» |
| memory | β
|
| extern | β
|
| instance | β
|
## Misc
| Feature | Status |
|-------------------|:------:|
| WAT | β
|
| WASI | β |
| Cross Compilation | β |
# License
The entire project is under the MIT License. Please read [the
`LICENSE` file][license].
[license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE