ez-php/opcache
最新稳定版本:1.11.0
Composer 安装命令:
composer require ez-php/opcache
包简介
OPcache preload script generator for the ez-php framework — scans class paths and writes a ready-to-use preload.php
README 文档
README
OPcache preload script generator for the ez-php framework.
Scans configured class directories and generates a ready-to-use preload.php that can be referenced by PHP's opcache.preload ini directive. Preloading compiles framework classes into shared memory at server startup, eliminating per-request file I/O and compilation overhead.
Installation
composer require ez-php/opcache
Registration
Add the service provider in provider/modules.php:
$app->register(\EzPhp\OPCache\PreloaderServiceProvider::class);
Configuration
Add config/opcache.php:
<?php return [ // Absolute path for the generated preload script. 'output_file' => base_path('preload.php'), // Directories to scan for PHP files. 'paths' => [ base_path('vendor/ez-php/framework/src'), base_path('vendor/ez-php/contracts/src'), base_path('app'), ], // Filename glob patterns to exclude. 'exclude' => [ '*Test.php', '*TestCase.php', '*Interface.php', ], // Set to true to use require_once instead of opcache_compile_file. // Useful when classes have cross-file dependencies that must be resolved // in the correct order. Defaults to false. 'require_once' => false, ];
Generating the preload script
Use the Preloader directly — for example from a Composer script or a deploy step:
use EzPhp\OPCache\PreloadConfig; use EzPhp\OPCache\Preloader; $config = new PreloadConfig( outputFile: '/var/www/html/preload.php', paths: [ '/var/www/html/vendor/ez-php/framework/src', '/var/www/html/vendor/ez-php/contracts/src', ], excludePatterns: ['*Test.php', '*TestCase.php'], ); $count = (new Preloader($config))->generate(); echo "Generated preload script with {$count} files.\n";
Or resolve it from the container after bootstrapping the application:
$preloader = $app->make(\EzPhp\OPCache\Preloader::class); $count = $preloader->generate();
Enabling preloading in php.ini
After generating the script, point PHP to it:
opcache.preload=/var/www/html/preload.php opcache.preload_user=www-data
Restart PHP-FPM or the web server after each change to the preload script.
Generated script format
<?php // Auto-generated OPcache preload script. // Generated by ez-php/opcache at 2026-03-29 12:00:00 // Total files: 42 // Usage: set opcache.preload=<this-file> in php.ini if (function_exists('opcache_compile_file')) { opcache_compile_file('/var/www/html/vendor/ez-php/framework/src/Application.php'); opcache_compile_file('/var/www/html/vendor/ez-php/framework/src/Container.php'); // ... }
Testing
No external services required — all tests run in-process using temporary directories.
composer test
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-29