A PHP library that provides optimized startup parameters for OPcache and JIT configuration to improve performance.
- 🚀 Automatic Detection: Detects OPcache and JIT support automatically
- ⚡ Performance Optimization: Provides optimized parameters for better performance
- 🔧 Flexible Configuration: Customizable OPcache and JIT settings
- 📊 Status Reporting: Get detailed information about optimization support
- =�� Safe Fallbacks: Gracefully handles unsupported environments
- PHP 8.0 or higher
- OPcache extension (recommended for JIT)
composer require tourze/php-startup-parameter-optimization<?php
use Tourze\PHPStartupParameterOptimization\PhpOptimizer;
$optimizer = new PhpOptimizer();
// Check if OPcache and JIT are supported
if ($optimizer->isOpcacheSupported()) {
echo "OPcache is supported\n";
}
if ($optimizer->isJitSupported()) {
echo "JIT is supported\n";
}
// Get optimized parameters
$parameters = $optimizer->getOptimizedParameters();
print_r($parameters);<?php
use Tourze\PHPStartupParameterOptimization\PhpOptimizer;
$optimizer = new PhpOptimizer();
$parameters = $optimizer->getOptimizedParameters();
// Execute PHP with optimized parameters
$command = 'php ' . implode(' ', $parameters) . ' your_script.php';
passthru($command);<?php
use Tourze\PHPStartupParameterOptimization\PhpOptimizer;
$optimizer = new PhpOptimizer();
// Get only OPcache parameters
$opcacheParams = $optimizer->getOpcacheParameters();
// Get only JIT parameters with custom buffer size
$jitParams = $optimizer->getJitParameters('200M');
// Get parameters with custom settings
$parameters = $optimizer->getOptimizedParameters(
enableOpcache: true,
enableJit: true,
jitBufferSize: '150M'
);<?php
use Tourze\PHPStartupParameterOptimization\PhpOptimizer;
$optimizer = new PhpOptimizer();
$status = $optimizer->getStatus();
echo "PHP Version: " . $status['php_version'] . "\n";
echo "OPcache Support: " . ($status['opcache'] ? 'Yes' : 'No') . "\n";
echo "JIT Support: " . ($status['jit'] ? 'Yes' : 'No') . "\n";
if (!empty($status['reasons'])) {
echo "Unsupported Reasons:\n";
foreach ($status['reasons'] as $feature => $reason) {
echo "- $feature: $reason\n";
}
}When OPcache is supported, the following parameters are applied:
opcache.enable_cli=1- Enable OPcache in CLI modeopcache.max_accelerated_files=50000- Maximum number of accelerated filesopcache.memory_consumption=256- OPcache memory consumption in MBopcache.interned_strings_buffer=16- Interned strings buffer in MBopcache.fast_shutdown=1- Enable fast shutdownopcache.validate_timestamps=0- Disable timestamp validation for production
When JIT is supported (PHP 8.0+), the following parameters are applied:
opcache.jit=tracing- Use tracing JIT modeopcache.jit_buffer_size=100M- JIT buffer size (default)opcache.jit_hot_loop=64- Hot loop thresholdopcache.jit_hot_func=127- Hot function thresholdopcache.jit_hot_return=127- Hot return thresholdopcache.jit_hot_side_exit=127- Hot side exit threshold
You can customize default values by extending the PhpOptimizer class:
class CustomPhpOptimizer extends PhpOptimizer
{
protected const DEFAULT_JIT_BUFFER_SIZE = '200M';
protected const DEFAULT_OPCACHE_MEMORY = 512;
protected const DEFAULT_OPCACHE_MAX_FILES = 100000;
}- Production Environment: Always disable
opcache.validate_timestampsin production - Memory Allocation: Adjust
opcache.memory_consumptionbased on your application size - JIT Buffer: Increase
opcache.jit_buffer_sizefor larger applications - File Count: Set
opcache.max_accelerated_fileshigher than your total file count
-
JIT not available
- Ensure PHP 8.0 or higher
- Check if OPcache extension is loaded
- Verify PHP was compiled with JIT support
-
OPcache not working
- Install and enable OPcache extension
- Check PHP configuration:
php -m | grep OPcache
-
Performance degradation
- Monitor OPcache statistics with
opcache_get_status() - Adjust memory settings if cache is full
- Monitor OPcache statistics with
<?php
use Tourze\PHPStartupParameterOptimization\PhpOptimizer;
$optimizer = new PhpOptimizer();
$status = $optimizer->getStatus();
// Debug information
var_dump($status);
// Check current OPcache status
if (function_exists('opcache_get_status')) {
var_dump(opcache_get_status());
}composer testContributions are welcome! Please feel free to submit a Pull Request.
This library is released under the MIT License. See the LICENSE file for details.
Please see CHANGELOG.md for more information on what has changed recently.