Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vimeo/psalm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.7.5
Choose a base ref
...
head repository: vimeo/psalm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.7.6
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Feb 24, 2023

  1. Disable opcache.preload if it's enabled

    Fixes #9382
    
    Also reorganized the opcache settings check a bit and enforced
    `opcache.jit_buffer_size`
    weirdan committed Feb 24, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    weirdan Bruce Weirdan
    Copy the full SHA
    ea32d20 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ae4ec68 View commit details
Showing with 52 additions and 14 deletions.
  1. +52 −14 src/Psalm/Internal/Fork/PsalmRestarter.php
66 changes: 52 additions & 14 deletions src/Psalm/Internal/Fork/PsalmRestarter.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
use function in_array;
use function ini_get;
use function preg_replace;
use function strlen;
use function strtolower;

use const PHP_VERSION_ID;

@@ -22,6 +24,14 @@
*/
class PsalmRestarter extends XdebugHandler
{
private const REQUIRED_OPCACHE_SETTINGS = [
'enable_cli' => true,
'jit' => 1205,
'jit_buffer_size' => 512 * 1024 * 1024,
'optimization_level' => '0x7FFEBFFF',
'preload' => '',
];

private bool $required = false;

/**
@@ -53,28 +63,54 @@ protected function requiresRestart($default): bool
static fn(string $extension): bool => extension_loaded($extension)
);

if (PHP_VERSION_ID >= 8_00_00 && (extension_loaded('opcache') || extension_loaded('Zend OPcache'))) {
$opcache_loaded = extension_loaded('opcache') || extension_loaded('Zend OPcache');

if (PHP_VERSION_ID >= 8_00_00 && $opcache_loaded) {
// 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;
}
$opcache_settings = [
'enable_cli' => in_array(ini_get('opcache.enable_cli'), ['1', 'true', true, 1]),
'jit' => (int) ini_get('opcache.jit'),
'optimization_level' => (string) ini_get('opcache.optimization_level'),
'preload' => (string) ini_get('opcache.preload'),
'jit_buffer_size' => self::toBytes(ini_get('opcache.jit_buffer_size')),
];

if (((int) ini_get('opcache.jit')) !== 1205) {
return true;
foreach (self::REQUIRED_OPCACHE_SETTINGS as $ini_name => $required_value) {
if ($opcache_settings[$ini_name] !== $required_value) {
return true;
}
}
}

if (((int) ini_get('opcache.jit')) === 0) {
return true;
}
return $default || $this->required;
}

if (ini_get('opcache.optimization_level') !== '0x7FFEBFFF') {
return true;
}
private static function toBytes(string $value): int
{
$unit = strtolower($value[strlen($value) - 1]);

if (in_array($unit, ['g', 'm', 'k'], true)) {
$value = (int) $value;
} else {
$unit = '';
$value = (int) $value;
}

return $default || $this->required;
switch ($unit) {
case 'g':
$value *= 1024;
// no break
case 'm':
$value *= 1024;
// no break
case 'k':
$value *= 1024;
}

return $value;
}


/**
* No type hint to allow xdebug-handler v1 and v2 usage
*
@@ -93,17 +129,19 @@ protected function restart($command): void
}

$additional_options = [];
$opcache_loaded = extension_loaded('opcache') || extension_loaded('Zend OPcache');

// 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'))) {
if (PHP_VERSION_ID >= 8_00_00 && $opcache_loaded) {
$additional_options = [
'-dopcache.enable_cli=true',
'-dopcache.jit_buffer_size=512M',
'-dopcache.jit=1205',
'-dopcache.optimization_level=0x7FFEBFFF',
'-dopcache.preload=',
];
}