hostbybelle/compressionbuffer
Composer 安装命令:
composer require hostbybelle/compressionbuffer
包简介
CompressionBuffer provides easy access to zstd, brotli, and gzip output buffering with PHP on any webserver.
README 文档
README
CompressionBuffer
CompressionBuffer provides easy access to zstd, brotli, and gzip output buffering with PHP on any web server. You can even get zstd output compression with the PHP development server.
Features
- Respects the
Accept-Encodingheader sent by the client, including the specified priority for each compression method. - Allows
zstd,brotli,gzipanddeflatecompression methods to be used on any web server. - All included compression methods have been benchmarked with compression levels carefully selected for the ideal balance between speed and size reduction.
- Auto-selects the compression method based on client headers and available PHP extensions.
- Automatically sends the appropriate headers.
Requirements
- A PHP application using output buffering.
PHP 8.0or greater.ext-brotliif you want brotli compression.ext-zstdif you want zstd compression.ext-zlibif you want gzip / deflate compression.
Installation & Usage
Install via composer:
composer require hostbybelle/compressionbuffer
Enabling in your application:
<?php use HostByBelle\CompressionBuffer; require 'vendor/autoload.php'; CompressionBuffer::setUp(); // Have compressionBuffer detect & sort the compression methods ob_start([CompressionBuffer::class, 'handler']); // Register it // Send some content to the output buffer echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"; // Finally send it to the browser & let CompressionBuffer do it's magic. ob_end_flush();
Toggling CompressionBuffer's status:
CompressionBuffer::enable(); // Enable output compression (enabled by default) CompressionBuffer::disable(); // Disable output compression CompressionBuffer::isEnabled(); // Check if it's currently enabled or not
Compression Method Tests & Results
Compression Methods, Ranked
zstdis the fastest, most efficient compression method. On it's lowest level it will be 4.5x faster thangzipwhile producing a 5% smaller output. When matchinggzipon it's fastest setting,zstdwill produce a 10% smaller output.brotliis a good middle-ground between the two alternatives. It's lowest setting is still about 3x faster thangzipwhile producing a 5% smaller output. It will produce a similar overall compression level tozstd, but will do so at a slower pace. Still an overall great choice.gzipis the longstanding, tried & true compression method, but is quite slow compared to the new alternatives and will produce larger outputs while doing so.
These stats are based off some simple testing we've performed on a 4mb HTML document containing the book war and peace. This choice was inspired by jab4/zstdtest & represents a large document a server might serve. Our testing with small documents shows all 3 compression methods have very similar compression levels and overall processing time.
The results of our testing can be found here on Google Sheets.
Compression Levels Used
zstd: Level 3. Level 4 would also be a good option as it will still be faster than the rest, however at level 3zstdfar exceeds the other options for speed while matching them in overall compression level and level 4 is only 38% the speed of level 3 for for only .4% more compression.brotli: Level 3. Level 4 does come with a noticeable increase to compression level, but does so in 3x the time. At level 3 brotli provides a similar compression level togzip, but at around 4.5x the speed.gzip: Level 4 was chosen as it's the highest level before gzip's speed quickly drops off to nearly unusable levels. This does come at a slight cost to overall compression level, but helps keep application response times quick.
hostbybelle/compressionbuffer 适用场景与选型建议
hostbybelle/compressionbuffer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.55k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hostbybelle/compressionbuffer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hostbybelle/compressionbuffer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-04-07