nytris / boost
v0.1.1
2024-08-21 01:47 UTC
Requires
- php: >=8.1
- asmblah/php-code-shift: ^0.1
- nytris/nytris: ^0.1
- psr/cache: ^1.0
Requires (Dev)
- mockery/mockery: 1.6.11
- phpstan/phpstan: ^1.10
- phpstan/phpstan-mockery: ^1.1
- phpunit/phpunit: ^10.2
This package is auto-updated.
Last update: 2024-09-23 00:24:54 UTC
README
提升PHP性能,尤其是在开启open_basedir
的情况下。
为什么?
open_basedir
禁用了PHP的realpath和stat缓存,这个库以可配置的方式重新实现了它们。- 即使
open_basedir
被禁用,原生的缓存也只存储在每个进程内。这个库允许使用PSR兼容的缓存来存储它们。
注意,对于原生的文件系统包装器(当这个库不被使用时)
stat
缓存只保留一个文件,最新的stat结果。- 还有一个类似的单个状态缓存用于
lstat
结果。
当使用时,这个库缓存了所有访问的文件的状态,而不仅仅是最近的一个。
使用方法
使用Composer安装此包
$ composer require nytris/boost
当使用Nytris平台(推荐)时
配置Nytris平台
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\FilesystemAdapter; $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 FilesystemAdapter( 'realpath', 0, $cachePath ), // Allows changing to avoid collisions if required. statCacheKey: 'stat_key', // Using Symfony Cache adapter as an example. statCachePoolFactory: fn (string $cachePath) => new FilesystemAdapter( 'stat', 0, $cachePath ), // Whether to hook `clearstatcache(...)`. hookBuiltinFunctions: true )); return $bootConfig;
当独立使用Boost时
尽可能早地将Boost加载到您的应用程序中,例如在/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(); } ...
另请参阅
- PHP Code Shift,这是该库使用的。