[wp-trac] [WordPress Trac] #36455: Call opcache_reset() after plug-in, theme or core update

WordPress Trac noreply at wordpress.org
Thu May 17 22:45:00 UTC 2018


#36455: Call opcache_reset() after plug-in, theme or core update
-------------------------------------+---------------------
 Reporter:  nigro.simone             |       Owner:  (none)
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  5.0
Component:  Upgrade/Install          |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+---------------------

Comment (by doc987):

 Replying to [[comment:40|pputzer]]:

 I think there's another alternative.  Updating files does not require a
 full opcache reset.  All that's really needed is to invalidate the opcache
 entries for the files that change.  Doing that would (a) leave the opcache
 intact for all other files, thereby avoiding the performance issue, and
 (b) prevent a broken site.  The new files could even be immediately loaded
 to the opcache.  The downside of course is that the invalidating is more
 complicated.  Resetting the whole opcache is as simple as calling
 [[http://php.net/manual/en/function.opcache-reset.php|opcache_reset()]].

 A single file can be invalidated with [[http://php.net/manual/en/function
 .opcache-invalidate.php|opcache_invalidate()]].  A single directory tree
 might have the corresponding opcache entries (if any) updated with
 something like the function below.

 {{{#!php
 <?php
 function compile_dir($path,$force=false){
    $iter=new \RecursiveIteratorIterator(new
 \RecursiveDirectoryIterator($path));
    foreach($iter as $file){
       $ext=$iter->getExtension();
       if(in_array($ext,['php','svg',/* other file extensions */])){
          $name=$file->getPathname();
          $cached=opcache_is_script_cached($name);
          if($force && $cached) opcache_invalidate($name);
          if($force || !$cached) opcache_compile_file($name);
       }
    }
 }

 }}}

 Invalidating files upon update has the additional performance advantage of
 allowing
 [[https://secure.php.net/manual/en/opcache.configuration.php#ini.opcache
 .validate-timestamps|opcache.validate_timestamps]] to be set to 0.

 If there was a problem, I suppose a logged in user could be given a button
 to force an opcache reset.  Too bad the opache is not an LRU cache
 (https://github.com/zendtech/ZendOptimizerPlus/issues/187).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/36455#comment:44>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list