PHP 8.2.32
Preview: preload.php Size: 3.32 KB
/home/ecopackply/www/demo/preload.php

<?php

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

use CodeIgniter\Boot;
use Config\Paths;

/*
 *---------------------------------------------------------------
 * Sample file for Preloading
 *---------------------------------------------------------------
 * See https://www.php.net/manual/en/opcache.preloading.php
 *
 * How to Use:
 *   0. Copy this file to your project root folder.
 *   1. Set the $paths property of the preload class below.
 *   2. Set opcache.preload in php.ini.
 *     php.ini:
 *     opcache.preload=/path/to/preload.php
 */

// Load the paths config file
require __DIR__ . '/app/Config/Paths.php';

// Path to the front controller
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);

class preload
{
    /**
     * @var array Paths to preload.
     */
    private array $paths = [
        [
            'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
            'exclude' => [
                // Not needed if you don't use them.
                '/system/Database/OCI8/',
                '/system/Database/Postgre/',
                '/system/Database/SQLite3/',
                '/system/Database/SQLSRV/',
                // Not needed for web apps.
                '/system/Database/Seeder.php',
                '/system/Test/',
                '/system/CLI/',
                '/system/Commands/',
                '/system/Publisher/',
                '/system/ComposerScripts.php',
                // Not Class/Function files.
                '/system/Config/Routes.php',
                '/system/Language/',
                '/system/bootstrap.php',
                '/system/util_bootstrap.php',
                '/system/rewrite.php',
                '/Views/',
                // Errors occur.
                '/system/ThirdParty/',
            ],
        ],
    ];

    public function __construct()
    {
        $this->loadAutoloader();
    }

    private function loadAutoloader(): void
    {
        $paths = new Paths();
        require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';

        Boot::preload($paths);
    }

    /**
     * Load PHP files.
     */
    public function load(): void
    {
        foreach ($this->paths as $path) {
            $directory = new RecursiveDirectoryIterator($path['include']);
            $fullTree  = new RecursiveIteratorIterator($directory);
            $phpFiles  = new RegexIterator(
                $fullTree,
                '/.+((?<!Test)+\.php$)/i',
                RecursiveRegexIterator::GET_MATCH,
            );

            foreach ($phpFiles as $key => $file) {
                foreach ($path['exclude'] as $exclude) {
                    if (str_contains($file[0], $exclude)) {
                        continue 2;
                    }
                }

                require_once $file[0];
                // Uncomment only for debugging (to inspect which files are included).
                // Never use this in production - preload scripts must not generate output.
                // echo 'Loaded: ' . $file[0] . "\n";
            }
        }
    }
}

(new preload())->load();

Directory Contents

Dirs: 6 × Files: 8

Name Size Perms Modified Actions
.idea DIR
- drwxr-xr-x 2026-01-24 07:52:54
Edit Download
app DIR
- drwxr-xr-x 2026-01-24 07:54:38
Edit Download
public DIR
- drwxr-xr-x 2026-01-27 08:03:35
Edit Download
system DIR
- drwxr-xr-x 2026-01-24 08:11:41
Edit Download
tests DIR
- drwxr-xr-x 2026-01-24 08:18:16
Edit Download
writable DIR
- drwxr-xr-x 2026-01-24 08:19:29
Edit Download
384 B lrw-r--r-- 2026-01-27 08:03:55
Edit Download
2.30 KB lrw-r--r-- 2026-01-24 07:52:40
Edit Download
2.33 KB lrw-r--r-- 2026-01-24 07:52:39
Edit Download
1.13 KB lrw-r--r-- 2026-01-24 07:52:41
Edit Download
2.43 KB lrw-r--r-- 2026-01-24 07:52:42
Edit Download
3.32 KB lrw-r--r-- 2026-01-24 07:52:43
Edit Download
2.67 KB lrw-r--r-- 2026-01-24 07:52:44
Edit Download
2.61 KB lrw-r--r-- 2026-01-24 07:52:45
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).