TYPO3 CMS  TYPO3_7-6
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  $xcVersion = phpversion('xcache');
33 
34  $supportedCaches = [
35  // The ZendOpcache aka OPcache since PHP 5.5
36  // http://php.net/manual/de/book.opcache.php
37  'OPcache' => [
38  'active' => extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1',
39  'version' => phpversion('Zend OPcache'),
40  'canReset' => true, // opcache_reset() ... it seems that it doesn't reset for current run.
41  // From documentation this function exists since first version (7.0.0) but from Changelog
42  // this function exists since 7.0.2
43  // http://pecl.php.net/package-changelog.php?package=ZendOpcache&release=7.0.2
44  'canInvalidate' => function_exists('opcache_invalidate'),
45  'error' => false,
46  'clearCallback' => function ($fileAbsPath) {
47  if ($fileAbsPath !== null && function_exists('opcache_invalidate')) {
48  opcache_invalidate($fileAbsPath);
49  } else {
50  opcache_reset();
51  }
52  }
53  ],
54 
55  // http://www.php.net/manual/de/book.wincache.php
56  'WinCache' => [
57  'active' => extension_loaded('wincache') && ini_get('wincache.ocenabled') === '1'
58  && version_compare(phpversion('wincache'), '2.0.0.0', '<'),
59  'version' => phpversion('wincache'),
60  'canReset' => true,
61  'canInvalidate' => true, // wincache_refresh_if_changed()
62  'error' => false,
63  'clearCallback' => function ($fileAbsPath) {
64  if ($fileAbsPath !== null) {
65  wincache_refresh_if_changed([$fileAbsPath]);
66  } else {
67  // No argument means refreshing all.
68  wincache_refresh_if_changed();
69  }
70  }
71  ],
72 
73  // http://xcache.lighttpd.net/
74  'XCache' => [
75  'active' => extension_loaded('xcache'),
76  'version' => $xcVersion,
77  'canReset' => !ini_get('xcache.admin.enable_auth'), // xcache_clear_cache()
78  'canInvalidate' => false,
79  'error' => false,
80  'clearCallback' => function ($fileAbsPath) {
81  if (!ini_get('xcache.admin.enable_auth')) {
82  xcache_clear_cache(XC_TYPE_PHP);
83  }
84  }
85  ],
86  ];
87 
88  $activeCaches = [];
89  foreach ($supportedCaches as $opcodeCache => $properties) {
90  if ($properties['active']) {
91  $activeCaches[$opcodeCache] = $properties;
92  }
93  }
94  return $activeCaches;
95  }
96 
104  public function clearAllActive($fileAbsPath = null)
105  {
106  foreach ($this->getAllActive() as $properties) {
107  $callback = $properties['clearCallback'];
108  $callback($fileAbsPath);
109  }
110  }
111 }