tourze / php-startup-parameter-optimization
PHP startup parameter optimization for OPcache and JIT configuration
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tourze/php-startup-parameter-optimization
Requires
- php: ^8.2
- composer-runtime-api: ^2.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
This package is auto-updated.
Last update: 2025-11-16 12:12:00 UTC
README
A PHP library that provides optimized startup parameters for OPcache and JIT configuration to improve performance.
Features
- 🚀 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
Requirements
- PHP 8.0 or higher
- OPcache extension (recommended for JIT)
Installation
composer require tourze/php-startup-parameter-optimization
Usage
Basic Usage
<?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);
Command Line Usage
<?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);
Custom Configuration
<?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' );
Status Information
<?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"; } }
Default Parameters
OPcache Parameters
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
JIT Parameters
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
Configuration Constants
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; }
Performance Tips
- 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
Troubleshooting
Common Issues
-
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
Debug Information
<?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()); }
Testing
composer test
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This library is released under the MIT License. See the LICENSE file for details.
Changelog
Please see CHANGELOG.md for more information on what has changed recently.