nytris/boost

Maintainers

Details

github.com/nytris/boost

Source

Issues

Installs: 2 988

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:project

v0.1.0 2023-09-14 23:57 UTC

This package is auto-updated.

Last update: 2024-04-15 01:09:05 UTC


README

Build Status

Improves PHP performance, especially when open_basedir is in effect.

Why?

  • open_basedir disables the PHP realpath and stat caches, this library re-implements them in a configurable way.
  • Even when open_basedir is disabled, the native caches are only stored per-process. This library allows them to be stored using a PSR-compliant cache.

Note that for the native filesystem wrapper (when this library is not in use):

  • The stat cache only keeps a single file, the most recent stat taken.
  • There is a separate similar one-stat cache for lstat results.

When in use, this library caches stats for all files accessed and not only the most recent one.

Usage

Install this package with Composer:

$ composer install nytris/boost

Now load it as early as possible in your application, for example a /bootstrap.php:

<?php

declare(strict_types=1);

use Nytris\Boost\Boost;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

require __DIR__ . '/vendor/autoload.php';

// Install Nytris Boost as early as possible so that as many files as possible are cached.
if (getenv('ENABLE_NYTRIS_BOOST') === 'yes') {
    (new Boost(
        realpathCachePool: new FilesystemAdapter(
            'nytris.realpath',
            0,
            __DIR__ . '/var/cache/'
        ),
        statCachePool: new FilesystemAdapter(
            'nytris.stat',
            0,
            __DIR__ . '/var/cache/'
        ),
        hookBuiltinFunctions: false
    ))->install();
}

...

See also