Skip to content

feat(opcache): load patched binaries into opcache shared memory (ZCSG) #121

Closed as not planned

Description

@lisachenko

Follow-up to the OpCache binary-file API (#111, merged). Explicitly deferred in docs/opcache-binary.md.

Today the patch→refresh loop is proven under opcache.file_cache_only=1; when opcache also uses shared memory, a resident script is only re-read after invalidation. The next step is to publish a patched image directly into the running accelerator's shared memory (ZCSG) so all workers pick it up without a file-cache round-trip.

Scope (research + implementation): bind the non-public opcache SHM entry points (zend_file_cache_script_load / zend_accel_hash_update / ZCSG(hash)), or an equivalent path, to install a patched zend_persistent_script into SHM safely across workers. This depends on opcache.so symbol visibility and careful locking; likely large and fragile across builds. Foundation for #121 (hot-swap wiring).

Activity

  1. added
    enhancementNew feature or request
    opcacheIssue is related to opcache integration. Either doesn't work well or behaves incorrect.
    on Aug 5, 2026
  2. lisachenko commented on Aug 19, 2026

    @lisachenko
    OwnerAuthor

    Closing as not planned — the feasibility spike (PR #265, full report in docs/research/zcsg-spike.md) concludes direct ZCSG publication is infeasible against stock opcache:

    • opcache.so exports only 6 default-visibility dynamic symbols; every write-path entry point (zend_shared_alloc, zend_accel_hash_update, zend_shared_alloc_lock, zend_accel_shared_protect, zend_file_cache_script_load, the ZCSG/accel_shared_globals pointer, the lock fd) is hidden-visibility and empirically un-bindable via FFI. No ini flag or z-engine change exports them.
    • The cross-process lock lives on an unreachable anonymous fd, and a userland SHM write SIGSEGVs under opcache.protect_memory=1 (the default-safe posture). No lock, no safe interned-string mutation, no crash atomicity — none mitigable.
    • The read side is reachable (the spike walks ZCSG(hash) live via the one exported smm_shared_globals), but that is not the hard part.

    The use case is already covered: BinaryCacheFile::refresh() drives opcache's own zend_file_cache_script_load() — the entire locked install — on a compile miss (proven by SharedMemoryRefreshTest, #125). Since FPM workers share one SHM segment, one faulting request republishes for all. Direct writes would only add push-without-a-warm-up-request, not worth racing every worker outside opcache's lock. The only sound route to that extra capability is a companion opcache/extension patch re-exporting the locked install path — a native artifact, which contradicts z-engine's stock-PHP premise, so out of scope for this library.

    The epic's possible/impossible matrix is updated accordingly: ZCSG direct writes = infeasible vs stock opcache; refresh() is the SHM publication mechanism.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopcacheIssue is related to opcache integration. Either doesn't work well or behaves incorrect.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions