⚠️ Advanced Users Only - This plugin is intended for system administrators and developers. It requires server-level access to modifyphp.iniand restart PHP processes.🚫 Not for Shared Hosting - OPcache preloading requires dedicated server access. This will NOT work on shared hosting environments where you don't have control over the PHP configuration.
A WordPress plugin that generates OPcache preload files based on runtime statistics with safety analysis.
OPcache Preload Generator analyzes your WordPress site's OPcache usage patterns and creates optimized preload files for PHP's OPcache preloading feature (PHP 7.4+).
The plugin automatically identifies which PHP files are most frequently accessed and would benefit most from preloading, while filtering out files that could cause issues.
You should use this plugin if:
- You manage your own server (VPS, dedicated, or cloud instance)
- You have SSH/root access to modify
php.ini - You can restart PHP-FPM or your web server
- You understand the implications of PHP preloading
Do NOT use this plugin if:
- You're on shared hosting (SiteGround, Bluehost, GoDaddy, etc.)
- You cannot access or modify
php.ini - You cannot restart your web server
- You're not comfortable with server administration
- Automatic File Detection - Uses OPcache statistics to identify hot files
- Smart Reference Algorithm - Uses WordPress core files as reference points for threshold calculation
- Safety Analysis - Filters files with side effects, dependency issues, or conflicts
- Interactive Threshold Slider - Visual control over how many files to include
- Context-Aware UI - Different workflows for new users, file generated, and active states
- File Preview - See which files will be included before generating
- PHP 7.4 or higher
- WordPress 5.3 or higher
- OPcache extension enabled
- Server access to configure php.ini
- Upload the plugin files to
/wp-content/plugins/opcache-preload-generator/ - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Settings → OPcache Preload (Network Admin for multisite)
- Click "Advanced Options" to expand settings
- Adjust the Hit Threshold slider:
- Lower % = more files, higher cutoff
- Higher % = fewer files, lower cutoff
- Review the Candidate Files Preview
- Click "Generate Preload File"
- Copy the PHP configuration shown
- Add to your
php.ini:opcache.preload=/path/to/wordpress/preload.php opcache.preload_user=www-data
- Restart PHP-FPM or your web server
Use "Regenerate Preload File" to update the preload file with current OPcache statistics. Recommended periodically or after major updates.
- Reference File Detection: Finds a WordPress core file (l10n.php, option.php, etc.) that's loaded on every request
- Threshold Calculation:
reference_hits × threshold_percentage = cutoff_hits - File Selection: Includes all files with
hits >= cutoff_hits - Safety Filtering: Excludes files with side effects or dependency issues
- Preload Generation: Creates a
preload.phpfile withopcache_compile_file()calls
opcache-preload-generator/
├── opcache-preload-generator.php # Plugin entry point
├── inc/
│ ├── class-plugin.php # Main plugin class
│ ├── class-opcache-analyzer.php # OPcache statistics analysis
│ ├── class-preload-generator.php # Preload file generation
│ ├── class-file-safety-analyzer.php # Safety checks
│ ├── class-admin-page.php # Admin UI
│ ├── class-ajax-handler.php # AJAX endpoints
│ └── ...
├── views/ # Admin templates
├── assets/ # CSS and JS
└── tests/ # PHPUnit tests
composer install
npm installvendor/bin/phpunitvendor/bin/phpcs
vendor/bin/phpcbf # Auto-fixThe plugin checks files for:
- Side Effects - Code that executes on include (echo, direct calls)
- Dependency Issues - Classes extending unavailable classes
- Define Conflicts - Multiple define() calls
- Path Constants - DIR/FILE usage in class properties
- Blacklisted Files - Known problematic WordPress core files
Why don't I see more files when lowering the threshold?
If all your cached files have high hit counts, lowering the threshold won't show more files. The cutoff is relative to the reference file's hit count.
Why does the reference file hit count keep increasing?
The reference file's hit count grows as the OPcache warms up. This is normal and expected.
Is preloading right for my site?
Best for production sites with stable code. Changes to preloaded files require a PHP-FPM restart.
GPLv3 or later. See LICENSE.
Created by David Stone - Multisite Ultimate