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 = array(
35  // The ZendOpcache aka OPcache since PHP 5.5
36  // http://php.net/manual/de/book.opcache.php
37  'OPcache' => array(
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' => array(
57  'active' => extension_loaded('wincache') && ini_get('wincache.ocenabled') === '1',
58  'version' => phpversion('wincache'),
59  'canReset' => true,
60  'canInvalidate' => true, // wincache_refresh_if_changed()
61  'error' => false,
62  'clearCallback' => function ($fileAbsPath) {
63  if ($fileAbsPath !== null) {
64  wincache_refresh_if_changed(array($fileAbsPath));
65  } else {
66  // No argument means refreshing all.
67  wincache_refresh_if_changed();
68  }
69  }
70  ),
71 
72  // http://xcache.lighttpd.net/
73  'XCache' => array(
74  'active' => extension_loaded('xcache'),
75  'version' => $xcVersion,
76  'canReset' => !ini_get('xcache.admin.enable_auth'), // xcache_clear_cache()
77  'canInvalidate' => false,
78  'error' => false,
79  'clearCallback' => function ($fileAbsPath) {
80  if (!ini_get('xcache.admin.enable_auth')) {
81  xcache_clear_cache(XC_TYPE_PHP);
82  }
83  }
84  ),
85  );
86 
87  $activeCaches = array();
88  foreach ($supportedCaches as $opcodeCache => $properties) {
89  if ($properties['active']) {
90  $activeCaches[$opcodeCache] = $properties;
91  }
92  }
93  return $activeCaches;
94  }
95 
103  public function clearAllActive($fileAbsPath = null)
104  {
105  foreach ($this->getAllActive() as $properties) {
106  $callback = $properties['clearCallback'];
107  $callback($fileAbsPath);
108  }
109  }
110 }