Skip to content

fix: restart worker scripts when opcache schedules a restart - #2843

Draft
nicolas-grekas wants to merge 1 commit into
php:mainfrom
nicolas-grekas:opcache-restart-workers
Draft

nicolas-grekas wants to merge 1 commit into
php:mainfrom
nicolas-grekas:opcache-restart-workers

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Contributor

A worker uses opcache's shared memory for as long as its script runs. When opcache schedules a restart of that memory, the worker keeps using memory that the restart reuses. Once php/php-src#24276 is merged, the worker blocks the restart instead. Caching then stays off for regular requests until the workers restart for another reason.

Worker scripts now restart at their next request boundary when a restart is scheduled, and idle ones right away. The thread isn't rebooted, the script ends and starts again. This happens at most once a minute. That way, a cache too small for the app can't restart the workers in a loop, which was the concern of #2564.

With php/php-src#24276, a worker that starts while the restart is pending isn't cached by opcache. The worker checks this with opcache_get_status() when it reaches frankenphp_handle_request(). Once the restart is done, the script starts again after its next request. CI can't cover this case without that fix, so I checked it locally on PHP 8.4 with the patch applied.

Draft until php/php-src#24276 is merged.

A worker uses opcache's shared memory for as long as its script runs. A
restart of that memory reuses memory the worker still references. Once
opcache waits for the threads of the process (php/php-src#24276), the restart
never runs while workers are alive.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant