Fixed PHP warning, when accessing OPcache status with opcache.restrict_api
See #58
This commit is contained in:
1 parent
752271b258
commit
cf1b0157fa
2 files changed
+22
-1
No files matched your search
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- PHP warning, when accessing OPcache status with `opcache.restrict_api`
|
||||||
|
|
||||||
## 3.3.6 - 2022-02-08
|
## 3.3.6 - 2022-02-08
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Core_Load_Collector implements Record_Collector_Interface {
|
|||||||
|
|
||||||
$php = 'PHP Load – ' . PHP_VERSION;
|
$php = 'PHP Load – ' . PHP_VERSION;
|
||||||
|
|
||||||
if ( function_exists( 'opcache_get_status' ) ) {
|
if ( $this->opcache_api_available() ) {
|
||||||
$zend_status = opcache_get_status();
|
$zend_status = opcache_get_status();
|
||||||
$php .= empty( $zend_status['opcache_enabled'] ) ? '' : ' – OPcache';
|
$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' ),
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user