11
11
use function array_splice ;
12
12
use function assert ;
13
13
use function count ;
14
- use function defined ;
15
14
use function extension_loaded ;
16
15
use function file_get_contents ;
17
16
use function file_put_contents ;
23
22
use function strlen ;
24
23
use function strtolower ;
25
24
26
- use const PHP_VERSION_ID ;
27
-
28
25
/**
29
26
* @internal
30
27
*/
31
28
final class PsalmRestarter extends XdebugHandler
32
29
{
33
- public const MIN_PHP_VERSION_WINDOWS_JIT = 8_04_03 ;
34
30
private const REQUIRED_OPCACHE_SETTINGS = [
35
31
'enable ' => 1 ,
36
32
'enable_cli ' => 1 ,
@@ -86,31 +82,31 @@ protected function requiresRestart($default): bool
86
82
static fn (string $ extension ): bool => extension_loaded ($ extension ),
87
83
);
88
84
89
- $ opcache_loaded = extension_loaded ('opcache ' ) || extension_loaded ('Zend OPcache ' );
85
+ if (!extension_loaded ('opcache ' ) && !extension_loaded ('Zend OPcache ' )) {
86
+ return true ;
87
+ }
90
88
91
- if ($ opcache_loaded ) {
92
89
// restart to enable JIT if it's not configured in the optimal way
93
- foreach (self ::REQUIRED_OPCACHE_SETTINGS as $ ini_name => $ required_value ) {
94
- $ value = (string ) ini_get ("opcache. $ ini_name " );
95
- if ($ ini_name === 'jit_buffer_size ' ) {
96
- $ value = self ::toBytes ($ value );
97
- } elseif ($ ini_name === 'enable_cli ' ) {
98
- $ value = in_array ($ value , ['1 ' , 'true ' , true , 1 ]) ? 1 : 0 ;
99
- } elseif (is_int ($ required_value )) {
100
- $ value = (int ) $ value ;
101
- }
102
- if ($ value !== $ required_value ) {
103
- return true ;
104
- }
90
+ foreach (self ::REQUIRED_OPCACHE_SETTINGS as $ ini_name => $ required_value ) {
91
+ $ value = (string ) ini_get ("opcache. $ ini_name " );
92
+ if ($ ini_name === 'jit_buffer_size ' ) {
93
+ $ value = self ::toBytes ($ value );
94
+ } elseif ($ ini_name === 'enable_cli ' ) {
95
+ $ value = in_array ($ value , ['1 ' , 'true ' , true , 1 ]) ? 1 : 0 ;
96
+ } elseif (is_int ($ required_value )) {
97
+ $ value = (int ) $ value ;
105
98
}
106
-
107
- $ requiredMemoryConsumption = $ this ->getRequiredMemoryConsumption ();
108
-
109
- if ((int )ini_get ('opcache.memory_consumption ' ) < $ requiredMemoryConsumption ) {
99
+ if ($ value !== $ required_value ) {
110
100
return true ;
111
101
}
112
102
}
113
103
104
+ $ requiredMemoryConsumption = self ::getRequiredMemoryConsumption ();
105
+
106
+ if ((int )ini_get ('opcache.memory_consumption ' ) < $ requiredMemoryConsumption ) {
107
+ return true ;
108
+ }
109
+
114
110
return $ default || $ this ->required ;
115
111
}
116
112
@@ -162,27 +158,23 @@ protected function restart($command): void
162
158
file_put_contents ($ this ->tmpIni , $ content );
163
159
}
164
160
165
- $ additional_options = [];
166
161
$ opcache_loaded = extension_loaded ('opcache ' ) || extension_loaded ('Zend OPcache ' );
167
162
168
163
// executed in the parent process (before restart)
169
164
// if it wasn't loaded then we apparently don't have opcache installed and there's no point trying
170
165
// to tweak it
171
- if ($ opcache_loaded &&
172
- !(defined ('PHP_WINDOWS_VERSION_MAJOR ' ) && PHP_VERSION_ID < self ::MIN_PHP_VERSION_WINDOWS_JIT )
173
- ) {
174
- $ additional_options = [];
175
- foreach (self ::REQUIRED_OPCACHE_SETTINGS as $ key => $ value ) {
176
- $ additional_options []= "-dopcache. {$ key }= {$ value }" ;
177
- }
166
+ $ additional_options = $ opcache_loaded ? [] : ['-dzend_extension=opcache ' ];
167
+ foreach (self ::REQUIRED_OPCACHE_SETTINGS as $ key => $ value ) {
168
+ $ additional_options []= "-dopcache. {$ key }= {$ value }" ;
169
+ }
178
170
179
- $ requiredMemoryConsumption = $ this -> getRequiredMemoryConsumption ();
171
+ $ requiredMemoryConsumption = self :: getRequiredMemoryConsumption ();
180
172
181
- if ((int )ini_get ('opcache.memory_consumption ' ) < $ requiredMemoryConsumption ) {
182
- $ additional_options []= "-dopcache.memory_consumption= {$ requiredMemoryConsumption }" ;
183
- }
173
+ if ((int )ini_get ('opcache.memory_consumption ' ) < $ requiredMemoryConsumption ) {
174
+ $ additional_options []= "-dopcache.memory_consumption= {$ requiredMemoryConsumption }" ;
184
175
}
185
176
177
+
186
178
array_splice (
187
179
$ command ,
188
180
1 ,
@@ -197,7 +189,7 @@ protected function restart($command): void
197
189
/**
198
190
* @return positive-int
199
191
*/
200
- private function getRequiredMemoryConsumption (): int
192
+ private static function getRequiredMemoryConsumption (): int
201
193
{
202
194
// Reserve for byte-codes
203
195
$ result = 256 ;
0 commit comments