1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OPCache; |
4
|
|
|
|
5
|
|
|
class OPCacheConfiguration { |
6
|
|
|
|
7
|
|
|
private $configurationData; |
8
|
|
|
|
9
|
|
|
public function __construct() { |
10
|
|
|
$this->configurationData = opcache_get_configuration(); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function getDirectives() { |
14
|
|
|
return $this->configurationData['directives']; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function getDirective($directive) { |
18
|
|
|
if (strpos($directive, 'opcache.') === FALSE) { |
19
|
|
|
$directive = 'opcache.' . $directive; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return ini_get($directive); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getDirectiveKeys() { |
26
|
|
|
return array( |
27
|
|
|
'opcache.enable', |
28
|
|
|
'opcache.enable_cli', |
29
|
|
|
'opcache.memory_consumption', |
30
|
|
|
'opcache.interned_strings_buffer', |
31
|
|
|
'opcache.max_accelerated_files', |
32
|
|
|
'opcache.wasted_percentage', |
33
|
|
|
'opcache.validate_timestamps', |
34
|
|
|
'opcache.revalidate_freq', |
35
|
|
|
'opcache.revalidate_path', |
36
|
|
|
'opcache.save_comments', |
37
|
|
|
'opcache.load_comments', |
38
|
|
|
'opcache.fast_shutdown', |
39
|
|
|
'opcache.enable_file_override', |
40
|
|
|
'opcache.optimization_level', |
41
|
|
|
'opcache.inherited_hack', |
42
|
|
|
'opcache.dups_fix', |
43
|
|
|
'opcache.blacklist_filename', |
44
|
|
|
'opcache.max_file_size', |
45
|
|
|
'opcache.consistency_checks', |
46
|
|
|
'opcache.force_restart_timeout', |
47
|
|
|
'opcache.error_log', |
48
|
|
|
'opcache.log_verbosity_level', |
49
|
|
|
'opcache.preferred_memory_model', |
50
|
|
|
'opcache.protect_memory', |
51
|
|
|
'opcache.mmap_base', |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getBlacklist() { |
56
|
|
|
return $this->configurationData['blacklist']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getVersion() { |
60
|
|
|
return $this->configurationData['version']; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function checkDirectives() { |
64
|
|
|
$recommended = array(); |
65
|
|
|
$required = array(); |
66
|
|
|
$severity = REQUIREMENT_OK; |
67
|
|
|
foreach ($this->getDirectiveKeys() as $directive) { |
68
|
|
|
if ($message = $this->recommendedDirectiveSetting($directive)) { |
69
|
|
|
$recommended[$directive] = $message; |
70
|
|
|
} |
71
|
|
|
if ($message = $this->requiredDirectiveSetting($directive)) { |
72
|
|
|
$required[$directive] = $message; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if (!empty($recommended)) { |
77
|
|
|
$severity = REQUIREMENT_WARNING; |
78
|
|
|
} |
79
|
|
|
if (!empty($required)) { |
80
|
|
|
$severity = REQUIREMENT_ERROR; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$messages = array_merge($recommended, $required); |
84
|
|
|
return array( |
85
|
|
|
'messages' => $messages, |
86
|
|
|
'severity' => $severity, |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
private function recommendedDirectiveSetting($directive) { |
|
|
|
|
91
|
|
|
$setting = $this->getDirective($directive); |
92
|
|
|
|
93
|
|
|
switch ($directive) { |
94
|
|
|
case 'opcache.validate_timestamps': |
95
|
|
|
if ($setting == TRUE) { |
|
|
|
|
96
|
|
|
return t('OPcache is still checking the timestamps of files to see if they have been updated. For maximum performance, set <tt>opcache.validate_timestamps = 0</tt> in your PHP installation’s configuration file, and use the “Clear all caches” button on the <a href="!perf_path">Performance page</a> to clear the OPcache cache after updating files (or use Drush).', array('!perf_path' => url('admin/config/development/performance'))); |
97
|
|
|
} |
98
|
|
|
break; |
99
|
|
|
default: |
100
|
|
|
break; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
private function requiredDirectiveSetting($directive) { |
|
|
|
|
105
|
|
|
$setting = $this->getDirective($directive); |
106
|
|
|
|
107
|
|
|
switch ($directive) { |
108
|
|
|
case 'opcache.save_comments': |
109
|
|
|
case 'opcache.load_comments': |
110
|
|
|
if ($setting == FALSE) { |
|
|
|
|
111
|
|
|
return t('Comment saving and/or loading is disabled. This functionality <em>must</em> be enabled, or Drupal will not function correctly. Ensure that you have <tt>opcache.save_comments = 1</tt> and <tt>opcache.load_comments = 1</tt> in this PHP installation’s configuration file.'); |
112
|
|
|
} |
113
|
|
|
break; |
114
|
|
|
default: |
115
|
|
|
break; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.