PHP code example of snapshotpl / preloader

1. Go to this page and download the library: Download snapshotpl/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/ */

    

snapshotpl / preloader example snippets




use DarkGhostHunter\Preloader\Preloader;

Preloader::make()->autoload(__DIR__ . '/vendor/autoloader.php')
    ->output(__DIR__.'/preloader.php')
    ->generate();

Preloader::make()->when(false); // You will never run, ha ha ha!

Preloader::make()->when(fn () => $app->cache()->get('should_run'));

Preloader::make()->whenHits(200000); // After a given number of hits.

Preloader::make()->whenOneIn(2000); // 1 in 2,000 chances.

Preloader::make()->overwrite()->whenOneIn(2000);

Preloader::make()->memory(32);

Preloader::make()->exclude([
    '/app/foo.php', 
    '/app/bar.php',
    '/app/quz/*.php'
]);

Preloader::make()->      '/app/foo.php', 
        '/app/bar.php',
        '/app/quz/*.php'
    ]);

Preloader::make()->append([
    '/app/foo.php', 
    '/app/bar.php',
    '/app/quz/*.php'
]);

Preloader::make()->memory(64)->append('foo.bar');

Preloader::make()->output(__DIR__ . '/../../my-preloader.php'); 

Preloader::make()->overwrite()->generate();

Preloader::make()->shouldCompile()->generate();

Preloader::make()->generate();

Preloader::make()->list();


// index.php

App::make();

$response = $app->run();

$response->sendToBrowser();

// A week after deployment
$weekAfterDeploy = $app->deploymentTimestamp() + (7*24*60*60);

// If a week has passed, and no script was created, do it!
\DarkGhostHunter\Preloader\Preloader::make()
    ->when(time() > $weekAfterDeploy)
    ->autoload(__DIR__ , '/../vendor/autoload.php')
    ->memory(256) // 256MB of memory limit
    ->output(PHP_LOCALSTATEDIR . '/preload.php') // put it in /var.
    ->generate();
ini
opcache.preload=/www/app/preload.php