1. Go to this page and download the library: Download diego-ninja/preloader 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/ */
diego-ninja / preloader example snippets
use Ninja\Preloader\Preloader;
Preloader::make()->writeTo(__DIR__.'/preloader.php');
use Ninja\Preloader\Preloader;
Preloader::make()->when(fn () => $app->cache()->get('should_run'));
use Ninja\Preloader\Preloader;
Preloader::make()->whenOneIn(50);
use Ninja\Preloader\Preloader;
Preloader::make()->append([
__DIR__ . '/files/*/more_files',
__DIR__ . '/classes/'
]);
use Symfony\Component\Finder\Finder;
use Ninja\Preloader\Preloader;
Preloader::make()->append(function (Finder $find) {
$find->files()->in('/package')->name(['*.php', '*.twig']);
});
use Ninja\Preloader\Preloader;
Preloader::make()->exclude([
__DIR__ . '/files/*/more_files',
__DIR__ . '/vendor'
]);
use Symfony\Component\Finder\Finder;
use Ninja\Preloader\Preloader;
Preloader::make()->exclude(function (Finder $find) {
$find->files()->in('/package')->name(['*.php', '*.twig']);
});
use Ninja\Preloader\Preloader;
Preloader::make()->selfExclude();
use Ninja\Preloader\Preloader;
Preloader::make()->memoryLimit(32);
use Ninja\Preloader\Preloader;
Preloader::make()->useRequire(__DIR__ . '/../vendor/autoload.php');
use Ninja\Preloader\Preloader;
Preloader::make()->ignoreNotFound();
use Ninja\Preloader\Preloader;
Preloader::make()->writeTo(__DIR__ . '/preloader.php');
use Ninja\Preloader\Preloader;
Preloader::make()->getList();
// /www/app/safe_preloader.php
register_shutdown_function(function (): void {
$error = error_get_last();
if (!$error) {
return;
}
echo 'Preloader Script has stopped with an error:' . \PHP_EOL;
echo 'Message: ' . $error['message'] . \PHP_EOL;
echo 'File: ' . $error['file'] . \PHP_EOL;
});
//
// index.php
use Framework\App;
use Ninja\Preloader\Preloader;
er();
Preloader::make()
->whenOneIn(100)
->memoryLimit(64)
->writeTo(PHP_LOCALSTATEDIR . '/preload.php'); // put it in /var.;
ini
opcache.preload=/www/app/preload.php
ini
opcache.preload=/www/app/safe_preloader.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.