Skip to content

Commit

Permalink
Merge pull request #9265 from weirdan/fix-opcache-loaded-twice
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 13, 2023
2 parents 5d1fe88 + 528ac00 commit 08f5b35
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use function ini_get;
use function preg_replace;

use const PHP_VERSION_ID;

/**
* @internal
*/
Expand Down Expand Up @@ -43,17 +45,20 @@ protected function requiresRestart($default): bool
$this->disabledExtensions,
static fn(string $extension): bool => extension_loaded($extension)
);
if (!extension_loaded('opcache')) {
return true;
}
if (!in_array(ini_get('opcache.enable_cli'), ['1', 'true', true, 1])) {
return true;
}
if (((int) ini_get('opcache.jit')) !== 1205) {
return true;
}
if (((int) ini_get('opcache.jit')) === 0) {
return true;

if (PHP_VERSION_ID >= 8_00_00 && (extension_loaded('opcache') || extension_loaded('Zend OPcache'))) {
// restart to enable JIT if it's not configured in the optimal way
if (!in_array(ini_get('opcache.enable_cli'), ['1', 'true', true, 1])) {
return true;
}

if (((int) ini_get('opcache.jit')) !== 1205) {
return true;
}

if (((int) ini_get('opcache.jit')) === 0) {
return true;
}
}

return $default || $this->required;
Expand All @@ -74,16 +79,26 @@ protected function restart(array $command): void

file_put_contents($this->tmpIni, $content);
}

$additional_options = [];

// executed in the parent process (before restart)
// if it wasn't loaded then we apparently don't have opcache installed and there's no point trying
// to tweak it
// If we're running on 7.4 there's no JIT available
if (PHP_VERSION_ID >= 8_00_00 && (extension_loaded('opcache') || extension_loaded('Zend OPcache'))) {
$additional_options = [
'-dopcache.enable_cli=true',
'-dopcache.jit_buffer_size=512M',
'-dopcache.jit=1205',
];
}

array_splice(
$command,
1,
0,
[
'-dzend_extension=opcache',
'-dopcache.enable_cli=true',
'-dopcache.jit_buffer_size=512M',
'-dopcache.jit=1205',
],
$additional_options,
);

parent::restart($command);
Expand Down

0 comments on commit 08f5b35

Please sign in to comment.