Skip to content

Add OPcache restart hook, fired when a restart is carried out - #23828

Open
nicolas-grekas wants to merge 1 commit into
php:masterfrom
nicolas-grekas:opcache-restart-hook
Open

nicolas-grekas wants to merge 1 commit into
php:masterfrom
nicolas-grekas:opcache-restart-hook

Conversation

@nicolas-grekas

@nicolas-grekas nicolas-grekas commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

After #15590, which added zend_accel_schedule_restart_hook.

That hook says a restart of OPcache's shared memory is coming, not that it happened: the restart runs later, at request startup, on whichever thread or process first finds the cache unused, and it can stay pending for a long time. This adds zend_accel_restart_hook, called on that thread once per restart, right after it completed and the SHM lock is released, with the same reason.

FrankenPHP needs it for its logs and metrics: under ZTS the restart rewinds shared memory that other threads may still reference, so the exact moment matters for post-mortems, and the scheduling event alone doesn't tell an operator whether the restart ran at all.

zend_accel_schedule_restart_hook tells an observer that a restart of
OPcache's shared memory is coming, but not whether or when it happens:
the restart runs later, at request startup, on whichever thread or
process first finds the cache unused, and it can stay pending for a
long time. This adds zend_accel_restart_hook, called on that thread once
per restart, right after the restart completed, with the same reason.
A threaded SAPI needs it for its logs and metrics, since the restart
rewinds shared memory that other threads may still reference.
@nicolas-grekas

Copy link
Copy Markdown
Contributor Author

Rebased. The hook is now called after the SHM lock is released, which is what dstogov asked for the first hook in #15590.

@arnaud-lb could you have a look? php/frankenphp#2634 is merged and reports scheduled restarts with the existing hook. This new hook is what's missing to report that the restart really happened.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant