‪TYPO3CMS  11.5
OpcodeCacheService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 {
31  public function ‪getAllActive(): array
32  {
33  $supportedCaches = [
34  'OPcache' => [
35  'active' => extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1',
36  'version' => phpversion('Zend OPcache'),
37  'warning' => ‪self::isClearable() ? false : 'Either opcache_invalidate or opcache_reset are disabled in this installation. Clearing will not work.',
38  'clearCallback' => static function ($fileAbsPath) {
39  if (self::isClearable()) {
40  if ($fileAbsPath !== null) {
41  opcache_invalidate($fileAbsPath);
42  } else {
43  opcache_reset();
44  }
45  }
46  },
47  ],
48  ];
49  $activeCaches = [];
50  foreach ($supportedCaches as $opcodeCache => $properties) {
51  if ($properties['active']) {
52  $activeCaches[$opcodeCache] = $properties;
53  }
54  }
55  return $activeCaches;
56  }
57 
63  public function ‪clearAllActive(?string $fileAbsPath = null): void
64  {
65  foreach ($this->‪getAllActive() as $properties) {
66  $callback = $properties['clearCallback'];
67  $callback($fileAbsPath);
68  }
69  }
70 
71  protected static function ‪isClearable(): bool
72  {
73  $disabled = explode(',', (string)ini_get('disable_functions'));
74  return function_exists('opcache_invalidate')
75  && function_exists('opcache_reset')
76  && !(in_array('opcache_invalidate', $disabled, true) || in_array('opcache_reset', $disabled, true));
77  }
78 }
‪TYPO3\CMS\Core\Service\OpcodeCacheService\clearAllActive
‪clearAllActive(?string $fileAbsPath=null)
Definition: OpcodeCacheService.php:63
‪TYPO3\CMS\Core\Service\OpcodeCacheService\isClearable
‪static isClearable()
Definition: OpcodeCacheService.php:71
‪TYPO3\CMS\Core\Service\OpcodeCacheService\getAllActive
‪array getAllActive()
Definition: OpcodeCacheService.php:31
‪TYPO3\CMS\Core\Service\OpcodeCacheService
Definition: OpcodeCacheService.php:25
‪TYPO3\CMS\Core\Service
Definition: AbstractService.php:16