Um tempo de execução WebAssembly completo e maduro para PHP baseado em Wasmer.
Fácil de usar : a API wasmer imita a API WebAssembly C padrão,
Rápido : wasmer executa os módulos WebAssembly o mais rápido possível, próximo à velocidade nativa ,
Seguro : todas as chamadas para WebAssembly serão rápidas, mas o mais importante, completamente seguras e em sandbox.
Para instalar a biblioteca, siga o clássico:
clone do git https://github.com/wasmerio/wasmer-phpcd wasmer-php/ext phpize ./configure --enable-wasmer fazer fazer testmake instalar
Nota: Wasmer ainda não funciona no Windows.
<?php declare(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 'Chamando de volta...' . PHP_EOL;echo '> Olá mundo!' . PHP_EOL;retorna nulo;
}$functype = wasm_functype_new(new WasmVecValType(), novo WasmVecValType());$func = wasm_func_new($store, $functype, 'hello_callback');wasm_functype_delete($functype);$extern = wasm_func_as_extern($func);$externs = novo WasmVecExtern([$extern]);$instance = wasm_instance_new($store, $module, $externs);wasm_func_delete($func);$exports = wasm_instance_exports($instance);$run = wasm_extern_as_func($exportações[0]);wasm_module_delete($module);wasm_instance_delete($instance);$resultados = 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);função hello_callback()
{echo 'Chamando de volta...'.PHP_EOL;echo '> Olá mundo!'.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();$resultados = $executar($args);Este exemplo cobre o caso de uso mais básico do Wasm: pegamos um módulo Wasm (em sua forma de representação de texto), criamos uma instância a partir dele, obtemos uma função exportada e a executamos.
Você pode ver exemplos mais avançados nos diretórios dedicados:
API processual
API orientada a objetos
| Plataforma | Arquitetura | Status |
|---|---|---|
| Linux | amd64 | |
| Linux | aarch64 | |
| Windows | amd64 | |
| Darwin | amd64 | |
| Darwin | aarch64 |
| PHP | Status |
|---|---|
| 8,0 | |
| 7.4 | |
| 7.3 |
| Compilador | Status |
|---|---|
| Guindaste | |
| LLVM | |
| Passagem única |
| Motor | Status |
|---|---|
| Nativo | |
| JIT | |
| Arquivo de objeto |
| Objeto | Status |
|---|---|
| configuração | |
| motor | |
| loja |
| Tipo | Status |
|---|---|
| tipo de valor | |
| tipo de função | |
| tipo global | |
| tipo de tabela | |
| tipo de memória | |
| tipo externo | |
| tipo de importação | |
| tipo de exportação |
| Objeto | Status |
|---|---|
| valor | |
| quadro | |
| armadilha | |
| estrangeiro | |
| módulo | |
| função | |
| global | |
| mesa | |
| memória | |
| externo | |
| exemplo |
| Recurso | Status |
|---|---|
| O QUE | |
| WASI | |
| Compilação Cruzada |
Todo o projeto está sob a licença do MIT. Por favor, leia o arquivo LICENSE .