Runtime WebAssembly yang lengkap dan matang untuk PHP berdasarkan Wasmer.
Mudah digunakan : API wasmer meniru API WebAssembly C standar,
Cepat : wasmer mengeksekusi modul WebAssembly secepat mungkin, mendekati kecepatan asli ,
Aman : Semua panggilan ke WebAssembly akan dilakukan dengan cepat, namun yang lebih penting, sepenuhnya aman dan terkotak pasir.
Untuk menginstal perpustakaan, ikuti yang klasik:
git clone https://github.com/wasmerio/wasmer-phpcd wasmer-php/ext phpize ./configure --aktifkan-wasmer membuat buat instalasi testmake
Catatan: Wasmer belum berfungsi di Windows.
<?php menyatakan(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 'Menelepon kembali...' . PHP_EOL;echo '> Halo Dunia!' . PHP_EOL;kembalikan nol;
}$functype = wasm_functype_new(WasmVecValType() baru, WasmVecValType());$func = wasm_func_new($store, $functype, 'hello_callback');wasm_functype_delete($functype);$extern = wasm_func_as_extern($func);$externs = baru 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, WasmVecVal() baru);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::baru($toko, $wasm);fungsi hello_callback()
{echo 'Menelepon kembali...'.PHP_EOL;echo '> Halo Dunia!'.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 = $jalankan($args);Contoh ini mencakup kasus penggunaan Wasm yang paling dasar: kita mengambil modul Wasm (dalam bentuk representasi teksnya), membuat sebuah instance dari modul tersebut, mendapatkan fungsi yang diekspor, dan menjalankannya.
Anda dapat melihat contoh lebih lanjut di direktori khusus:
API Prosedural
API berorientasi objek
| Platform | Arsitektur | Status |
|---|---|---|
| Linux | amd64 | |
| Linux | aarch64 | |
| jendela | amd64 | |
| Darwin | amd64 | |
| Darwin | aarch64 |
| PHP | Status |
|---|---|
| 8.0 | |
| 7.4 | |
| 7.3 |
| Penyusun | Status |
|---|---|
| Angkat derek | |
| LLVM | |
| tiket tunggal |
| Mesin | Status |
|---|---|
| Warga asli | |
| JIT | |
| File Objek |
| Obyek | Status |
|---|---|
| konfigurasi | |
| mesin | |
| toko |
| Jenis | Status |
|---|---|
| tipe val | |
| tipe fungsi | |
| tipe global | |
| tipe tablet | |
| tipe memori | |
| tipe eksternal | |
| tipe impor | |
| tipe ekspor |
| Obyek | Status |
|---|---|
| val | |
| bingkai | |
| perangkap | |
| luar negeri | |
| modul | |
| fungsi | |
| global | |
| meja | |
| ingatan | |
| eksternal | |
| contoh |
| Fitur | Status |
|---|---|
| APA | |
| WSASI | |
| Kompilasi Silang |
Seluruh proyek berada di bawah Lisensi MIT. Silakan baca file LICENSE .