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 1 commit
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
27 changes: 18 additions & 9 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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;
}
Expand All @@ -74,16 +74,25 @@ 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 (extension_loaded('opcache') || extension_loaded('Zend OPcache')) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zend OPcache is what the extension called on my system:

$ php -r 'var_dump(["opcache" => extension_loaded("opcache"), "Zend OPcache" => extension_loaded("Zend OPcache")]);'
array(2) {
  'opcache' =>
  bool(false)
  'Zend OPcache' =>
  bool(true)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the opcache_get_status function is more reliable, as I did in https://github.com/vimeo/psalm/pull/9240/files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it may be less reliable as it can throw warnings depending on the configuration: https://www.php.net/opcache_get_status#refsect1-function.opcache-get-status-errors

$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