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');$ule_wasm'); $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_exptern_extern_extern_exunc_$ex); = new WasmVecExtern([$extern]);$instance = wasm_instance_new($store, $module, $externs);wasm_func_delete($func);$exports = wasm_instance_exports($instance);$run = wasm_extern_func( );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 = $導出[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文件。