Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opcache being loaded twice #9265

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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