open-southeners/laravel-vapor-response-compression
最新稳定版本:3.2.1
Composer 安装命令:
composer require open-southeners/laravel-vapor-response-compression
包简介
Add server-side response compression with a range of different algorithms (Gzip, brotli, deflate...)
关键字:
README 文档
README
Add server-side response compression to Laravel with a range of different algorithms (Gzip, brotli, deflate...)
Why use this package?
The reason why is because AWS hard limit its API Gateway service to 10MB (at the date of writing this), and by hard we mean that there's no way you can increase this limitation.
Note: Thought CloudFlare is a good solution for the end user, it doesn't solve this issue as CloudFlare does this between the server and the client, so the response already passed through AWS (API Gateway).
Read more here: https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#http-api-quotas
Or on our blog article: https://opensoutheners.com/how-to-prevent-large-responses-to-trigger-502-errors
Getting started
composer require open-southeners/laravel-vapor-response-compression
Then publish the configuration file defaults into your application's config folder:
php artisan vendor:publish --tag=response-compression
Then add the following to you app/Http/Kernel.php as a global middleware:
Note: Remember this is different in older versions of Laravel, Laravel 9 should look like the following.
/** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array<string, array<int, class-string|string>> */ protected $middleware = [ // ... \OpenSoutheners\LaravelResponseCompression\ResponseCompression::class, ];
Configuration
If you already have this config/response-compression.php file, you can skip this step, otherwise please use the following artisan command first:
php artisan vendor:publish --tag=response-compression
Note: As for smaller responses this threshold will prevent to compress the response if it doesn't reach an specific number of bytes. We encourage you to configure this and not leave it as ±0 bytes otherwise response will be always compressed.
This configuration is defaulted to 10000 bytes, you may customise this as your application demands.
Setting up Brotli and/or ZStandard extensions in Vapor
First of all, this will require you to use Docker containers on your Vapor environments if you're not familiar with them, you can still use this extension as it uses the first client requested algorithm available at server side.
???? Read more about using containers in Vapor here
Brotli
Anyway, in case you want to proceed, add this to your environment Dockerfile(s), please use comments as references only:
# FROM laravelphp/vapor:php84 RUN apk add --no-cache brotli # COPY . /var/task
And ensure your project depends on vdechenaux/brotli.
Alternative Brotli setup
Another alternative is to use: https://github.com/kjdev/php-ext-brotli
pecl install brotli
# FROM laravelphp/vapor:php84 RUN pecl install brotli \ && docker-php-ext-enable brotli \ # COPY . /var/task
ZStandard
Using https://github.com/kjdev/php-ext-zstd
pecl install zstd
# FROM laravelphp/vapor:php84 RUN pecl install zstd \ && docker-php-ext-enable zstd \ # COPY . /var/task
Lz4
Using https://github.com/kjdev/php-ext-lz4
Note: Only Debian or RHEL packages here, Vapor uses Alpine as base images so no luck here...
sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install php-lz4
Credits
- To @jryd_13 for writing the article that gave me this idea
- To @kjdev for supporting PHP with all his amazing extensions used here for different compression algorithms
open-southeners/laravel-vapor-response-compression 适用场景与选型建议
open-southeners/laravel-vapor-response-compression 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 129.99k 次下载、GitHub Stars 达 15, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「vapor」 「open-southeners」 「response-compression」 「laravel-vapor」 「gzip-compression」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 open-southeners/laravel-vapor-response-compression 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 open-southeners/laravel-vapor-response-compression 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 open-southeners/laravel-vapor-response-compression 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Build a dynamic list of trusted proxies for use with Laravel Vapor
This package can log incoming requests to the cloud watch for laravel vapor application.
A utility written in PHP8.1+ to convert multiple-byte units with no dependencies
An artisan command to assist deploying your Laravel Vapor app to multiple AWS regions
Integrate JSON:API resources on your Laravel API project.
Integrate data transfer objects into Laravel, the easiest way
统计信息
- 总下载量: 129.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知