wasmer php
1.1.0
基于 Wasmer 的完整且成熟的 PHP WebAssembly 运行时。
易于使用: wasmer API 模仿标准 WebAssembly C API,
快速: wasmer尽可能快地执行 WebAssembly 模块,接近本机速度,
安全:对 WebAssembly 的所有调用都将很快,但更重要的是,完全安全且沙箱化。
要安装该库,请遵循经典:
git 克隆 https://github.com/wasmerio/wasmer-phpcd wasmer-php/ext phpize ./configure --enable-wasmer 制作 进行测试安装
注意:Wasmer 尚不能在 Windows 上运行。
<?php 声明(strict_types=1);$engine = wasm_engine_new();$store = wasm_store_new($engine);$wasm = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'hello.wasm');$module = wasm_module_new($store, $wasm);function hello_callback() {echo '回拨...' 。 PHP_EOL;echo '> 你好世界!' 。 PHP_EOL;返回空;
}$functype = wasm_functype_new(new WasmVecValType(), new WasmVecValType());$func = wasm_func_new($store, $functype, 'hello_callback');wasm_functype_delete($functype);$extern = wasm_func_as_extern($func);$externs = 新WasmVecExtern([$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 WasmVecVal());wasm_store_delete($store);wasm_engine_delete($engine); <?phpdeclare(strict_types=1);use Wasm;require_once __DIR__.'/../vendor/autoload.php';$engine = WasmEngine::new();$store = WasmStore::new($engine);$ wasm = file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'hello.wasm');$module = WasmModule::new($store, $wasm);函数 hello_callback()
{echo '回调...'.PHP_EOL;echo '> Hello World!'.PHP_EOL;return null;
}$functype = WasmFunctype::new(new WasmVecValType(), new WasmVecValType());$func = WasmModuleFunc::new($store, $functype, 'hello_callback');$extern = $func->asExtern(); $externs = new WasmVecExtern([$extern->inner()]);$instance = WasmModuleInstance::new($store, $module, $externs);$exports = $instance->exports();$run = $exports[0]->asFunc();$args = new WasmVecVal();$results = $run($args);此示例涵盖了最基本的 Wasm 用例:我们采用 Wasm 模块(以其文本表示形式),从中创建一个实例,获取导出的函数并运行它。
您可以在专用目录中查看更高级的示例:
程序化API
面向对象的API
| 平台 | 建筑学 | 地位 |
|---|---|---|
| Linux | amd64 | |
| Linux | aarch64 | |
| 视窗 | amd64 | |
| 达尔文 | amd64 | |
| 达尔文 | aarch64 |
| PHP | 地位 |
|---|---|
| 8.0 | |
| 7.4 | |
| 7.3 |
| 编译器 | 地位 |
|---|---|
| 起重机 | |
| LLVM | |
| 单程 |
| 引擎 | 地位 |
|---|---|
| 本国的 | |
| 准时生产 | |
| 目标文件 |
| 目的 | 地位 |
|---|---|
| 配置 | |
| 引擎 | |
| 店铺 |
| 类型 | 地位 |
|---|---|
| 值类型 | |
| 函数类型 | |
| 全局类型 | |
| 表类型 | |
| 记忆类型 | |
| 外部类型 | |
| 导入类型 | |
| 出口类型 |
| 目的 | 地位 |
|---|---|
| 瓦尔 | |
| 框架 | |
| 陷阱 | |
| 外国的 | |
| 模块 | |
| 功能 | |
| 全球的 | |
| 桌子 | |
| 记忆 | |
| 外部的 | |
| 实例 |
| 特征 | 地位 |
|---|---|
| 瓦特 | |
| 瓦西 | |
| 交叉编译 |
整个项目都在麻省理工学院的许可下。请阅读LICENSE文件。