Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Last active January 15, 2023 00:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMorel/f91e9f1d1ba35d9d357ceb106052edfe to your computer and use it in GitHub Desktop.
Save BenMorel/f91e9f1d1ba35d9d357ceb106052edfe to your computer and use it in GitHub Desktop.
Generates a php.ini file compatible with PHP JIT compiler
<?php
/**
* Generates a php.ini file from runtime ini directives, excluding extensions incompatible with JIT.
* I did not find a way to disable an extension from the command line, so this script is a workaround.
*
* Use it this way:
*
* php generate-jit-php-ini.php > php.ini
* php -n -c php.ini
*/
declare(strict_types=1);
$zendExtensions = [
'opcache.so',
];
$disableExtensions = [
// These extensions are not compatible with JIT
'xdebug.so',
'pcov.so',
// Not sure why, but on my setup enabling these extensions yields:
// PHP Warning: Module "xxx" is already loaded in Unknown on line 0
'pdo_sqlite.so',
'pdo.so',
'posix.so',
];
/**
* @var string $name
* @var ?string $value
*/
foreach (ini_get_all(details: false) as $name => $value) {
if ($value === null) {
continue;
}
if ($name === 'extension_dir') {
$i = new DirectoryIterator($value);
foreach ($i as $file) {
/** @var SplFileInfo $file */
if (!$file->isFile() || $file->getExtension() !== 'so') {
continue;
}
if (in_array($file->getFilename(), $disableExtensions, true)) {
continue;
}
$directiveName = in_array($file->getFilename(), $zendExtensions, true)
? 'zend_extension'
: 'extension';
printf("%s=\"%s\"\n", $directiveName, $file->getPathname());
}
continue;
}
printf("%s=\"%s\"\n", $name, $value);
}
echo "opcache.jit_buffer_size=256M\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment