Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.77k stars 893 forks source link

Yoast updates delete opcache for non-Yoast and non-WordPress PHP files #20654

Open csurtyoung opened 1 year ago

csurtyoung commented 1 year ago

[x] I've read and understood the contribution guidelines. [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened

In wp-seo-main.php, function wpseo_init() contains the following code:

        if ( version_compare( WPSEO_Options::get( 'version', 1 ), WPSEO_VERSION, '<' ) ) {
                if ( function_exists( 'opcache_reset' ) ) {
                        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Prevent notices when opcache.restrict_api is set.
                        @opcache_reset();
                }

                new WPSEO_Upgrade();
                // Get a cleaned up version of the $options.
        }

Especially in complex environments with many sites running Yoast and other PHP applications present, dumping cache for the entire server repeatedly is harmful and poor practice. We have tracked an intermittent server stability issue to Yoast updates.

Please consider replacing the opcache_reset() call with opcache_invalidate() applied to the plugin files only. If this is not possible, please consider adding an advanced configuration option that disables the opcache_reset() call.

Previous discussion of this issue is present in https://github.com/Yoast/wordpress-seo/issues/9315. The issue was closed without being resolved at that time (2018) despite complaint from several users.

Further information can be viewed in Wordpress.org support thread (https://wordpress.org/support/topic/yoast-updates-delete-opcache-for-non-yoast-and-non-wp-php-files/)

To Reproduce

Step-by-step reproduction instructions

  1. Update Yoast
  2. Observe opcache state

Expected results

  1. opcache entries for Yoast files are invalidated, forcing refresh of cached versions of these particular files.

Actual results

  1. Entire opcache is reset, impacting non-Yoast and non-WordPress PHP code coexisting with Yoast on the server.

Technical info

Used versions

jeroenrotty commented 1 year ago

Hey @csurtyoung,

Thank you so much for creating this issue. I'll take it to the dev team and discuss, we might look into using wp_opcache_invalidate_directory() available since WP 6.2. (link)

csurtyoung commented 1 year ago

Thanks, Jeroen. I'll stay tuned and definitely appreciate that you and your team are receptive to this suggestion.

enricobattocchi commented 9 months ago

Reopening the issue since the solution was reverted in 21.9.1

hadamlenz commented 3 weeks ago

the opcache resetting for each subsite in a large multisite corrupts the cache. Variable letters start shifting, mostly in the require functions in wp-settings.php, which leads to white screen errors. Resetting the entire cache is a bit greedy. please stahp