定制 nytris/boost 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nytris/boost

最新稳定版本:v0.1.5

Composer 安装命令:

composer create-project nytris/boost

包简介

README 文档

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 require nytris/boost

When using Nytris platform (recommended)

Configure Nytris platform:

nytris.config.php

<?php

declare(strict_types=1);

use Nytris\Boost\BoostPackage;
use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Symfony\Component\Cache\Adapter\ApcuAdapter;

$bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/'));

$bootConfig->installPackage(new BoostPackage(
    // Allows changing to avoid collisions if required.
    realpathCacheKey: 'realpath_key',

    // Using Symfony Cache adapter as an example.
    realpathCachePoolFactory: fn (string $cachePath) => new ApcuAdapter(
        namespace: 'realpath',
        defaultLifetime: 0
    ),

    // Allows changing to avoid collisions if required.
    statCacheKey: 'stat_key',

    // Using Symfony Cache adapter as an example.
    statCachePoolFactory: fn (string $cachePath) => new ApcuAdapter(
        namespace: 'stat',
        defaultLifetime: 0
    ),

    // Whether to hook `clearstatcache(...)`.
    hookBuiltinFunctions: true
));

return $bootConfig;

When using Boost standalone

Load Boost 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\ApcuAdapter;

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 ApcuAdapter(
            namespace: 'nytris.realpath',
            defaultLifetime: 0
        ),
        statCachePool: new ApcuAdapter(
            namespace: 'nytris.stat',
            defaultLifetime: 0
        ),
        hookBuiltinFunctions: false
    ))->install();
}

...

Known issues / limitations

Using a filesystem-based cache such as Symfony Cache's FilesystemAdapter for the realpath or stat caches, for example, may cause infinite recursion, which can result in a segfault even with Xdebug enabled.

The solution is to avoid using filesystem-based caches for the filesystem data caches, which makes little sense in any case when the purpose of Boost is to reduce or avoid filesystem I/O.

See also

统计信息

  • 总下载量: 10.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-09