Skip to content

Commit c105211

Browse files
authored
Ensure that opcache.memory_consumption is enough (#11243)
1 parent d8cbc21 commit c105211

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Psalm/Internal/Fork/PsalmRestarter.php

+31
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ protected function requiresRestart($default): bool
103103
return true;
104104
}
105105
}
106+
107+
$requiredMemoryConsumption = $this->getRequiredMemoryConsumption();
108+
109+
if ((int)ini_get('opcache.memory_consumption') < $requiredMemoryConsumption) {
110+
return true;
111+
}
106112
}
107113

108114
return $default || $this->required;
@@ -169,6 +175,12 @@ protected function restart($command): void
169175
foreach (self::REQUIRED_OPCACHE_SETTINGS as $key => $value) {
170176
$additional_options []= "-dopcache.{$key}={$value}";
171177
}
178+
179+
$requiredMemoryConsumption = $this->getRequiredMemoryConsumption();
180+
181+
if ((int)ini_get('opcache.memory_consumption') < $requiredMemoryConsumption) {
182+
$additional_options []= "-dopcache.memory_consumption={$requiredMemoryConsumption}";
183+
}
172184
}
173185

174186
array_splice(
@@ -181,4 +193,23 @@ protected function restart($command): void
181193

182194
parent::restart($command);
183195
}
196+
197+
/**
198+
* @return positive-int
199+
*/
200+
private function getRequiredMemoryConsumption(): int
201+
{
202+
// Reserve for byte-codes
203+
$result = 256;
204+
205+
if (isset(self::REQUIRED_OPCACHE_SETTINGS['jit_buffer_size'])) {
206+
$result += self::REQUIRED_OPCACHE_SETTINGS['jit_buffer_size'] / 1024 / 1024;
207+
}
208+
209+
if (isset(self::REQUIRED_OPCACHE_SETTINGS['interned_strings_buffer'])) {
210+
$result += self::REQUIRED_OPCACHE_SETTINGS['interned_strings_buffer'];
211+
}
212+
213+
return $result;
214+
}
184215
}

0 commit comments

Comments
 (0)