TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
OpcodeCacheService.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Service;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 {
30  public function getAllActive()
31  {
32  $supportedCaches = [
33  // The ZendOpcache aka OPcache since PHP 5.5
34  // http://php.net/manual/de/book.opcache.php
35  'OPcache' => [
36  'active' => extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1',
37  'version' => phpversion('Zend OPcache'),
38  'canReset' => true, // opcache_reset() ... it seems that it doesn't reset for current run.
39  // From documentation this function exists since first version (7.0.0) but from Changelog
40  // this function exists since OPcache 7.0.2
41  // http://pecl.php.net/package-changelog.php?package=ZendOpcache&release=7.0.2
42  // PHP 7.0 onward is delivered minimum OPcache 7.0.6-dev
43  'canInvalidate' => true,
44  'error' => false,
45  'clearCallback' => function ($fileAbsPath) {
46  if ($fileAbsPath !== null) {
47  opcache_invalidate($fileAbsPath);
48  } else {
49  opcache_reset();
50  }
51  }
52  ],
53  ];
54 
55  $activeCaches = [];
56  foreach ($supportedCaches as $opcodeCache => $properties) {
57  if ($properties['active']) {
58  $activeCaches[$opcodeCache] = $properties;
59  }
60  }
61  return $activeCaches;
62  }
63 
71  public function clearAllActive($fileAbsPath = null)
72  {
73  foreach ($this->getAllActive() as $properties) {
74  $callback = $properties['clearCallback'];
75  $callback($fileAbsPath);
76  }
77  }
78 }