OpCodeCache.php 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Drupal\Component\Utility;
  3. /**
  4. * Provides helpers to handle PHP opcode caches.
  5. *
  6. * @ingroup utility
  7. */
  8. class OpCodeCache {
  9. /**
  10. * Checks if OpCodeCache is enabled.
  11. *
  12. * @return bool
  13. * TRUE if opcache is enabled, FALSE otherwise.
  14. */
  15. public static function isEnabled() {
  16. return extension_loaded('Zend OPcache') && ini_get('opcache.enable');
  17. }
  18. /**
  19. * Invalidates a PHP file from a possibly active opcode cache.
  20. *
  21. * In case the opcode cache does not support to invalidate an individual file,
  22. * the entire cache will be flushed.
  23. *
  24. * @param string $pathname
  25. * The absolute pathname of the PHP file to invalidate.
  26. */
  27. public static function invalidate($pathname) {
  28. clearstatcache(TRUE, $pathname);
  29. // Check if the Zend OPcache is enabled and if so invalidate the file.
  30. if (function_exists('opcache_invalidate')) {
  31. opcache_invalidate($pathname, TRUE);
  32. }
  33. }
  34. }