diff --git a/CHANGELOG.md b/CHANGELOG.md index fe57197..835f0b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed +- PHP warning, when accessing OPcache status with `opcache.restrict_api` + ## 3.3.6 - 2022-02-08 ### Changed diff --git a/src/Record/Collector/Core_Load_Collector.php b/src/Record/Collector/Core_Load_Collector.php index 2750387..24937d2 100644 --- a/src/Record/Collector/Core_Load_Collector.php +++ b/src/Record/Collector/Core_Load_Collector.php @@ -36,7 +36,7 @@ class Core_Load_Collector implements Record_Collector_Interface { $php = 'PHP Load – ' . PHP_VERSION; - if ( function_exists( 'opcache_get_status' ) ) { + if ( $this->opcache_api_available() ) { $zend_status = opcache_get_status(); $php .= empty( $zend_status['opcache_enabled'] ) ? '' : ' – OPcache'; } @@ -52,4 +52,22 @@ class Core_Load_Collector implements Record_Collector_Interface { new Record( $load, $timestart, $this->timeload - $timestart, '', 'core' ), ]; } + + private function opcache_api_available(): bool { + if ( ! function_exists( 'opcache_get_status' ) ) { + return false; + } + + $restrict_api = ini_get( 'opcache.restrict_api' ); + + if ( ! $restrict_api ) { + return true; + } + + /** + * The paths aren't normalized, because it is unclear if they are in PHP itself + * and this should rather be false negative to prevent warning emitted. + */ + return 0 === stripos( __FILE__, $restrict_api ); + } }