PHP code example of ez-php / opcache

1. Go to this page and download the library: Download ez-php/opcache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ez-php / opcache example snippets


$app->register(\EzPhp\OPCache\PreloaderServiceProvider::class);



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 

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";

$preloader = $app->make(\EzPhp\OPCache\Preloader::class);
$count = $preloader->generate();



// 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');
    // ...
}
bash
composer 
ini
opcache.preload=/var/www/html/preload.php
opcache.preload_user=www-data