Yan
Yan
CDCloudflare Developers
Created by Yan on 6/15/2024 in #workers-help
Import #30 "wasi_snapshot_preview1" "sock_accept": function import requires a callable
Hi. I'm having trouble executing PHP WASI under Cloudflare worker and can't understand what is actually wrong. It is always fails with the Import #30 "wasi_snapshot_preview1" "sock_accept": function import requires a callable. Is it some missing support for a standard on Cloudflare end or it needs to be compiled in special way? I would be grateful for any hints on the matter. What I'm trying to achieve is to run php-cgi WASI build from https://github.com/vmware-labs/webassembly-language-runtimes/tree/main/php/v8.2.6 When I try to run wasmtime with the same binary it works without any issues wasmtime php-cgi-8.2.6.wasm -i worker.js
import { WASI } from '@cloudflare/workers-wasi';
import PHPCGI from './php-cgi-8.2.6.wasm';

export default {
async fetch(request, _env, ctx) {
const stdout = new TransformStream();
const wasi = new WASI({
args: ['-i'],
stdout: stdout.writable,
});

const instance = new WebAssembly.Instance(PHPCGI, {
wasi_snapshot_preview1: wasi.wasiImport,
});

ctx.waitUntil(wasi.start(instance));

return new Response(stdout.readable, {
headers: { 'content-type': 'text/html' },
});
},
};
import { WASI } from '@cloudflare/workers-wasi';
import PHPCGI from './php-cgi-8.2.6.wasm';

export default {
async fetch(request, _env, ctx) {
const stdout = new TransformStream();
const wasi = new WASI({
args: ['-i'],
stdout: stdout.writable,
});

const instance = new WebAssembly.Instance(PHPCGI, {
wasi_snapshot_preview1: wasi.wasiImport,
});

ctx.waitUntil(wasi.start(instance));

return new Response(stdout.readable, {
headers: { 'content-type': 'text/html' },
});
},
};
wrangler.toml
#:schema node_modules/wrangler/config-schema.json
name = "round-morning-127d"
main = "worker.js"
compatibility_date = "2024-06-10"

preserve_file_names = true
#:schema node_modules/wrangler/config-schema.json
name = "round-morning-127d"
main = "worker.js"
compatibility_date = "2024-06-10"

preserve_file_names = true
3 replies