メインコンテンツへスキップ

proxyFileSystem

Callable

  • proxyFileSystem(sourceOfTruth: PHP, replica: PHP, paths: string[]): Promise<void>

  • Mounts directories from one PHP instance's filesystem into another using PROXYFS.

    This enables file sharing between PHP instances without duplicating the files in memory. For example, mounting /wordpress from the parent instance into a child worker allows both to access the same WordPress installation without copying the entire directory.

    The function automatically patches PROXYFS with mmap support before mounting on PHP 7+, so libraries like ICU can memory-map data files through the proxied filesystem.

    Legacy PHP (< 7) skips the mmap patch. PHP 5.x's zend_compile_file calls mmap() via zend_stream_fixup and trusts fstat() for the buffer size. When a file is pre-populated in MEMFS before PROXYFS is mounted over that path (e.g. php.ini written by preRun), fstat() can return the stale MEMFS size instead of the PROXYFS size, causing the parser to read past the real EOF and report spurious syntax errors. Without the mmap patch, Emscripten returns ENOSYS from mmap() and PHP falls back to a read-based path that handles size mismatches gracefully. PHP 7+ removed the mmap path from zend_stream_fixup entirely, so the patch is both safe and needed there (for ICU/intl).

    Mounts are registered via php.mount() so they survive runtime rotation. When the replica's WASM module is hot-swapped, hotSwapPHPRuntime() re-applies these mount handlers on the fresh module.


    Parameters

    • sourceOfTruth: PHP

      The PHP instance containing the original files

    • replica: PHP

      The PHP instance that will access files through PROXYFS

    • paths: string[]

      Absolute paths to mount (e.g., ['/wordpress', '/internal/shared'])

    Returns Promise<void>