Skip to content

Support multiple workers for NODEFS /wordpress mounts – Asyncify #2317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e117f79
Remove JSPI guards on multiple CLI workers
brandonpayton Jul 1, 2025
b0772c6
Make it possible to step debug more of libc
brandonpayton Jul 2, 2025
b51ad28
Correct asyncify name of fd_close
brandonpayton Jul 2, 2025
20e63f5
Add more asyncify declarations from asyncify sqlite tests
brandonpayton Jul 2, 2025
f0e0b4a
Use large ASYNCIFY_STACK_SIZE to try to address "unreachable" error
brandonpayton Jul 2, 2025
8e213ba
Expose more php-wasm build warnings
brandonpayton Jul 2, 2025
0ee13d8
Wrap calls in Asyncify.handleAsync()
brandonpayton Jul 2, 2025
fa6ef8f
Use Asyncify.handleSleep() as other async code does
brandonpayton Jul 2, 2025
082be5c
Try alternate prefixes for relevant ASYNCIFY_IMPORTS
brandonpayton Jul 3, 2025
c216fe0
Merge branch 'trunk' into add-multi-worker-asyncify-support
brandonpayton Jul 3, 2025
098f007
Reproducible crash with `PHP=7.4 node --loader=./packages/meta/src/n…
adamziel Jul 5, 2025
b69cdbe
Move comlink message passing to a separate messageport
adamziel Jul 7, 2025
58290e1
fd_close working with workers!
adamziel Jul 7, 2025
ba2ef49
Integrate locks with both Asyncify and JSPI in both the same thread a…
adamziel Jul 7, 2025
1232c52
Use synchronous messaging via Comlink in Asyncify build and asynchron…
adamziel Jul 7, 2025
192e986
Cleanup
adamziel Jul 7, 2025
25b0733
docstring
adamziel Jul 7, 2025
e1c70f2
Document the Node locking library
adamziel Jul 7, 2025
f5d427e
Document exposeFileLockManager()
adamziel Jul 7, 2025
e041176
Cleanup
adamziel Jul 7, 2025
4c34ded
Cleanup
adamziel Jul 7, 2025
0eede5b
Cleanup
adamziel Jul 7, 2025
ff9cbc8
Merge branch 'trunk' into add-multi-worker-asyncify-support
adamziel Jul 7, 2025
800c314
Lint
adamziel Jul 7, 2025
fe174a4
Lint
adamziel Jul 7, 2025
99014ab
Lint
adamziel Jul 7, 2025
28d6b24
Lint
adamziel Jul 7, 2025
20a898c
lint
adamziel Jul 8, 2025
ba6bc30
lint
adamziel Jul 8, 2025
0e5387b
lint
adamziel Jul 8, 2025
572eaea
Use 5000ms timeout in the sync message passing
adamziel Jul 8, 2025
801a8b3
lint
adamziel Jul 8, 2025
ea4cb3c
Add unit tests for the sync protocol
adamziel Jul 8, 2025
042387f
typecheck
adamziel Jul 8, 2025
129e530
remove comlink and biome from package.json deps
adamziel Jul 8, 2025
36bb1d0
Skip comlink symlink tests on Node < 23
adamziel Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"ajv": "8.12.0",
"async-lock": "1.4.1",
"classnames": "^2.3.2",
"comlink": "^4.4.2",
"crc-32": "1.2.2",
"diff3": "0.0.4",
"express": "4.21.2",
Expand Down
5 changes: 4 additions & 1 deletion packages/php-wasm/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@php-wasm/universal';
import type { SupportedPHPVersion } from '@php-wasm/universal';

import { FileLockManagerForNode } from '@php-wasm/node';
import { PHP } from '@php-wasm/universal';
import { loadNodeRuntime, useHostFilesystem } from '@php-wasm/node';
import path from 'path';
Expand Down Expand Up @@ -76,6 +77,8 @@ ${process.argv[0]} ${process.execArgv.join(' ')} ${process.argv[1]}
const php = new PHP(
await loadNodeRuntime(phpVersion, {
emscriptenOptions: {
fileLockManager: new FileLockManagerForNode(),
processId: 1,
ENV: {
...envVariables,
TMPDIR: sysTempDir,
Expand Down Expand Up @@ -109,7 +112,7 @@ ${process.argv[0]} ${process.execArgv.join(' ')} ${process.argv[1]}
})
);

response.exitCode
await response.exitCode
.catch((result) => {
if (result.name === 'ExitStatus') {
process.exit(result.status === undefined ? 1 : result.status);
Expand Down
48 changes: 42 additions & 6 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ RUN set -euxo pipefail; \
export PHP_VERSION_ESCAPED="${PHP_VERSION//./_}"; \
echo -n " -fdebug-compilation-dir=${DEBUG_DWARF_COMPILATION_DIR}/ " \
"-fdebug-prefix-map=/root/php_wasm.c=${DEBUG_DWARF_COMPILATION_DIR}/compile/php/php_wasm.c " \
"-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=./=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=/root/php-src/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=./=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/php-src/ " \
"-fdebug-prefix-map=/emsdk/emscripten/==${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ " \
"-fdebug-prefix-map=/root/emsdk/upstream/emscripten/=${OUTPUT_DIR_ON_HOST}/${PHP_VERSION_ESCAPED}/emscripten/ " \
>> /root/.emcc-php-wasm-flags; \
if [ "${WITH_SOURCEMAPS}" = "yes" ]; then \
echo -n ' -gsource-map' >> /root/.emcc-php-wasm-flags; \
Expand Down Expand Up @@ -615,11 +617,21 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"_js_popen_to_file",\n\
"_asyncjs__js_popen_to_file",\n\
"__syscall_fcntl64",\n\
"___syscall_fcntl64",\n\
"_asyncjs___syscall_fcntl64",\n\
"js_release_file_locks",\n\
"_js_release_file_locks",\n\
"_async_js_release_file_locks",\n\
"js_flock",\n\
"_js_flock",\n\
"_async_js_flock",\n\
"js_fd_read",\n\
"_js_fd_read",\n\
"fd_close",\n\
"_fd_close",\n\
"_asyncjs__fd_close",\n\
"close",\n\
"_close",\n\
"js_module_onMessage",\n\
"_js_module_onMessage",\n\
"_asyncjs__js_module_onMessage",\n\
Expand All @@ -632,7 +644,15 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"_wasm_shutdown",\n\
"_asyncjs__wasm_shutdown"]'; \
echo -n " -s ASYNCIFY_IMPORTS=$ASYNCIFY_IMPORTS " | tr -d "\n" >> /root/.emcc-php-asyncify-flags; \
export ASYNCIFY_ONLY_UNPREFIXED=$'"__fseeko_unlocked",\
export ASYNCIFY_ONLY_UNPREFIXED=$'"null.<anonymous>",\
"__stdio_close",\
"zend_stream_stdio_closer",\
"zend_destroy_file_handle",\
"php_init_config",\
"zend_register_ini_entries_ex",\
"php_module_startup",\
"wasm_sapi_module_startup",\
"__fseeko_unlocked",\
"__ftello_unlocked",\
"__funcs_on_exit",\
"__fwritex",\
Expand Down Expand Up @@ -849,6 +869,9 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"zif_stream_select",\
"_php_stream_fill_read_buffer",\
"_php_stream_read",\
"php_sqlite3_object_free_storage",\
"php_sqlite3_error",\
"sqlite3_reset",\
"php_stream_read_to_str",\
"php_userstreamop_read",\
"zif_fread",\
Expand All @@ -858,6 +881,7 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"zif_fwrite",\
"php_stdiop_write",\
"zif_array_filter",\
"zend_unclean_zval_ptr_dtor",\
"zend_call_known_instance_method_with_2_params",\
"zend_fetch_dimension_address_read_R",\
"_zval_dtor_func_for_ptr",\
Expand Down Expand Up @@ -1656,6 +1680,7 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"zend_hash_reverse_apply",\
"ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER",\
"zend_include_or_eval",\
"compile_filename",\
"zend_internal_type_error",\
"zend_interrupt_helper_SPEC",\
"zend_invalid_class_constant_type_error",\
Expand Down Expand Up @@ -1965,6 +1990,14 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
"zim_sqlite3_backup",\
"zim_SQLite3_backup",\
"zim_SQLite3_exec",\
"zim_sqlite3_exec",\
"zim_sqlite3_query",\
"zim_sqlite3_querySingle",\
"zim_sqlite3result_fetchArray",\
"php_cli_startup",\
"php_stdiop_close",\
"zend_parse_ini_file",\
"php_embed_startup",\
"zip_source_file_common_new",\
"zip_source_function_create",\
"zip_source_layered_create",\
Expand Down Expand Up @@ -2062,7 +2095,7 @@ RUN set -euxo pipefail; \
export OPTIMIZATION_FLAGS="-O0"; \
fi; \
PLATFORM_SPECIFIC_ARGS=''; \
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ] && [ "$WITH_JSPI" = "yes" ]; then \
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS -DPHP_WASM_FILE_LOCKING_SUPPORT=1"; \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS --js-library /root/phpwasm-emscripten-library-dynamic-linking.js"; \
PLATFORM_SPECIFIC_ARGS="$PLATFORM_SPECIFIC_ARGS --js-library /root/phpwasm-emscripten-library-file-locking-for-node.js -Wl,--wrap=getpid"; \
Expand Down Expand Up @@ -2240,6 +2273,9 @@ RUN set -euxo pipefail; \
if [ "${WITH_SOURCEMAPS}" = "yes" ] || [ "${WITH_DEBUG}" = "yes" ]; then \
# Make PHP source available for use with step debugger
rm -rf /root/php-src/.git; \
cp -r /root/php-src "/root/output/${PHP_VERSION_ESCAPED}/php-src"; \
cp -r /root/emsdk/upstream/emscripten/system "/root/output/${PHP_VERSION_ESCAPED}/php-src/system"; \
cp -r /root/php-src /root/output/"${PHP_VERSION_ESCAPED}"/php-src; \
# Copy emscripten source files
mkdir -p /root/output/"${PHP_VERSION_ESCAPED}"/emscripten; \
cp -r /root/emsdk/upstream/emscripten/cache /root/output/"${PHP_VERSION_ESCAPED}"/emscripten/; \
cp -r /root/emsdk/upstream/emscripten/system /root/output/"${PHP_VERSION_ESCAPED}"/emscripten/; \
fi;
Loading