You are running wp-cli and see this error message:
1 | Unable to query OPcache status: array_key_exists(): Argument #2 ($array) must be of type array, bool given. |
This error is thrown when opcache_get_status( true )
is called and returns false
because opcache is disabled and then array_key_exist looks for a 'scripts' in a bool instead of an array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | // wp-content/plugins/flush-opcache/admin/class-flush-opcache-admin.php /** * Where OPcache is actually flushed */ public function flush_opcache_reset() { $opcache_scripts = array (); if ( function_exists( 'opcache_get_status' ) ) { try { $raw = opcache_get_status( true ); if ( array_key_exists ( 'scripts' , $raw ) ) { foreach ( $raw [ 'scripts' ] as $script ) { /* Remove files outside of WP */ if ( false === strpos ( $script [ 'full_path' ], get_home_path() ) && false === strpos ( $script [ 'full_path' ], ABSPATH ) ) { continue ; } array_push ( $opcache_scripts , $script [ 'full_path' ] ); } } } catch ( \Throwable $e ) { error_log ( sprintf( 'Unable to query OPcache status: %s.' , $e ->getMessage() ), $e ->getCode() ); // phpcs:ignore } } foreach ( $opcache_scripts as $file ) { wp_opcache_invalidate( $file , true ); } } |
Cause: opcache is installed but not enabled for the cli
1 2 3 | php -i | grep -i opcache | grep enable opcache. enable => On => On opcache.enable_cli => Off => Off |
Work-a-round: find the opcache cli ini file and turn opcache on for the cli
1 2 | php -i | grep -i opcache | grep ini /etc/php/8 .2 /cli/conf .d /10-opcache .ini, |
Edit the cli opcache ini and set opcache.enable_cli
to on
1 2 3 | sudo vim /etc/php/8 .2 /cli/conf .d /10-opcache .ini # add on or true or 1 to turn it on opcache.enable_cli=on |
On Ubuntu 22.04 the in file will look as follows:

1 2 3 4 5 6 | lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy |
0 Comments