@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 110 lines 3.8 kB view raw
1<?php 2 3final class PhabricatorOpcodeCacheSpec extends PhabricatorCacheSpec { 4 5 public static function getActiveCacheSpec() { 6 $spec = new PhabricatorOpcodeCacheSpec(); 7 8 if (extension_loaded('Zend OPcache')) { 9 $spec->initOpcacheSpec(); 10 } else { 11 $spec->initNoneSpec(); 12 } 13 14 return $spec; 15 } 16 17 private function initOpcacheSpec() { 18 $this 19 ->setName(pht('Zend OPcache')) 20 ->setVersion(phpversion('Zend OPcache')); 21 22 if (ini_get('opcache.enable')) { 23 $this 24 ->setIsEnabled(true) 25 ->setClearCacheCallback('opcache_reset'); 26 27 $status = opcache_get_status(); 28 $memory = $status['memory_usage']; 29 30 $mem_used = $memory['used_memory']; 31 $mem_free = $memory['free_memory']; 32 $mem_junk = $memory['wasted_memory']; 33 $this->setUsedMemory($mem_used + $mem_junk); 34 $this->setTotalMemory($mem_used + $mem_junk + $mem_free); 35 $this->setEntryCount($status['opcache_statistics']['num_cached_keys']); 36 37 $is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); 38 39 $validate = ini_get('opcache.validate_timestamps'); 40 $freq = ini_get('opcache.revalidate_freq'); 41 if ($is_dev && (!$validate || $freq)) { 42 $summary = pht( 43 'OPcache is not configured properly for development.'); 44 45 $message = pht( 46 'In development, OPcache should be configured to always reload '. 47 'code so nothing needs to be restarted after making changes. To do '. 48 'this, enable "%s" and set "%s" to 0.', 49 'opcache.validate_timestamps', 50 'opcache.revalidate_freq'); 51 52 $this 53 ->newIssue('extension.opcache.devmode') 54 ->setShortName(pht('OPcache Config')) 55 ->setName(pht('OPcache Not Configured for Development')) 56 ->setSummary($summary) 57 ->setMessage($message) 58 ->addPHPConfig('opcache.validate_timestamps') 59 ->addPHPConfig('opcache.revalidate_freq') 60 ->addPhabricatorConfig('phabricator.developer-mode'); 61 } else if (!$is_dev && $validate) { 62 $summary = pht('OPcache is not configured ideally for production.'); 63 64 $message = pht( 65 'In production, OPcache should be configured to never '. 66 'revalidate code. This will slightly improve performance. '. 67 'To do this, disable "%s" in your PHP configuration.', 68 'opcache.validate_timestamps'); 69 70 $this 71 ->newIssue('extension.opcache.production') 72 ->setShortName(pht('OPcache Config')) 73 ->setName(pht('OPcache Not Configured for Production')) 74 ->setSummary($summary) 75 ->setMessage($message) 76 ->addPHPConfig('opcache.validate_timestamps') 77 ->addPhabricatorConfig('phabricator.developer-mode'); 78 } 79 } else { 80 $this->setIsEnabled(false); 81 82 $summary = pht('Enabling OPcache will dramatically improve performance.'); 83 $message = pht( 84 'The PHP "Zend OPcache" extension is installed, but not enabled in '. 85 'your PHP configuration. Enabling it will dramatically improve '. 86 'performance. Edit the "%s" setting to enable the extension.', 87 'opcache.enable'); 88 89 $this->newIssue('extension.opcache.enable') 90 ->setShortName(pht('OPcache Disabled')) 91 ->setName(pht('Zend OPcache Not Enabled')) 92 ->setSummary($summary) 93 ->setMessage($message) 94 ->addPHPConfig('opcache.enable'); 95 } 96 } 97 98 private function initNoneSpec() { 99 $message = pht( 100 'Installing the "Zend OPcache" extension will dramatically improve '. 101 'performance.'); 102 103 $this 104 ->newIssue('extension.opcache') 105 ->setShortName(pht('OPcache')) 106 ->setName(pht('Zend OPcache Not Installed')) 107 ->setMessage($message) 108 ->addPHPExtension('Zend OPcache'); 109 } 110}