2022-05-08 09:13:27 +09:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*---------------------------------------------------------------
|
|
|
|
* Sample file for Preloading
|
|
|
|
*---------------------------------------------------------------
|
|
|
|
* See https://www.php.net/manual/en/opcache.preloading.php
|
|
|
|
*
|
|
|
|
* How to Use:
|
2022-12-04 18:52:22 +09:00
|
|
|
* 0. Copy this file to your project root folder.
|
|
|
|
* 1. Set the $paths property of the preload class below.
|
2022-05-08 09:13:27 +09:00
|
|
|
* 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);
|
|
|
|
|
2022-06-07 07:17:32 +07:00
|
|
|
class preload
|
2022-05-08 09:13:27 +09:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array Paths to preload.
|
|
|
|
*/
|
|
|
|
private array $paths = [
|
|
|
|
[
|
2024-03-02 13:08:34 +07:00
|
|
|
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
|
2022-05-08 09:13:27 +09:00
|
|
|
'exclude' => [
|
|
|
|
// Not needed if you don't use them.
|
|
|
|
'/system/Database/OCI8/',
|
|
|
|
'/system/Database/Postgre/',
|
2024-03-02 09:31:58 +07:00
|
|
|
'/system/Database/SQLite3/',
|
2022-05-08 09:13:27 +09:00
|
|
|
'/system/Database/SQLSRV/',
|
2024-08-09 11:13:55 +09:00
|
|
|
// Not needed for web apps.
|
2022-05-08 09:13:27 +09:00
|
|
|
'/system/Database/Seeder.php',
|
|
|
|
'/system/Test/',
|
|
|
|
'/system/CLI/',
|
|
|
|
'/system/Commands/',
|
|
|
|
'/system/Publisher/',
|
|
|
|
'/system/ComposerScripts.php',
|
2024-08-09 11:13:55 +09:00
|
|
|
// Not Class/Function files.
|
|
|
|
'/system/Config/Routes.php',
|
|
|
|
'/system/Language/',
|
|
|
|
'/system/bootstrap.php',
|
|
|
|
'/system/rewrite.php',
|
2022-05-08 09:13:27 +09:00
|
|
|
'/Views/',
|
|
|
|
// Errors occur.
|
|
|
|
'/system/ThirdParty/',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->loadAutoloader();
|
|
|
|
}
|
|
|
|
|
2024-04-19 12:04:20 +09:00
|
|
|
private function loadAutoloader(): void
|
2022-05-08 09:13:27 +09:00
|
|
|
{
|
|
|
|
$paths = new Config\Paths();
|
2024-04-19 12:04:20 +09:00
|
|
|
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';
|
|
|
|
|
|
|
|
CodeIgniter\Boot::preload($paths);
|
2022-05-08 09:13:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load PHP files.
|
|
|
|
*/
|
2024-04-19 12:04:20 +09:00
|
|
|
public function load(): void
|
2022-05-08 09:13:27 +09:00
|
|
|
{
|
|
|
|
foreach ($this->paths as $path) {
|
|
|
|
$directory = new RecursiveDirectoryIterator($path['include']);
|
|
|
|
$fullTree = new RecursiveIteratorIterator($directory);
|
|
|
|
$phpFiles = new RegexIterator(
|
|
|
|
$fullTree,
|
|
|
|
'/.+((?<!Test)+\.php$)/i',
|
2025-01-13 11:03:02 +08:00
|
|
|
RecursiveRegexIterator::GET_MATCH,
|
2022-05-08 09:13:27 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($phpFiles as $key => $file) {
|
|
|
|
foreach ($path['exclude'] as $exclude) {
|
|
|
|
if (str_contains($file[0], $exclude)) {
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once $file[0];
|
|
|
|
echo 'Loaded: ' . $file[0] . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 07:17:32 +07:00
|
|
|
(new preload())->load();
|