chrisguitarguy/request-id-bundle
Composer 安装命令:
composer require chrisguitarguy/request-id-bundle
包简介
Add request IDs to to your Symfony requests.
关键字:
README 文档
README
This adds request ID's to your Symfony application. Why? It's a great way to add some additional information to logs and to present to users. For example, if an exception is thrown you'll be able to show the user the request ID which they can pass on to you to locate their specific issue.
Installation
Use Composer.
composer require chrisguitarguy/request-id-bundle
Then enable the bundle in your AppKernel.
use Symfony\Component\HttpKernel\Kernel; class AppKernel extends Kernel { public function registerBundles() { $bundles = [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), // ... new Chrisguitarguy\RequestId\ChrisguitarguyRequestIdBundle(), ]; // ... return $bundles; } // ... }
Configuration
# in app/config/config.yml chrisguitarguy_request_id: # The header which the bundle inspects for the incoming request ID # if this is not set an ID will be generated and set at this header request_header: Request-Id # Whether or not to trust the incoming request header. This is turned # on by default. If true a value in the `Request-Id` header in the request # will be used as the request ID for the rest of the request. If false # those values are ignored. trust_request_header: true # The header which the bundle will set the request ID to on # the response response_header: Request-Id # The service key of an object that implements # Chrisguitarguy\RequestId\RequestIdStorage # optional, defaults to `SimpleIdStorage` storage_service: ~ # The service key of an object that implements # Chrisguitarguy\RequestId\RequestIdGenerator # optional, defaults to a UUID v4 based generator generator_service: ~ # Whether or not to add the monolog process (see below), defaults to true enable_monolog: true # Whether or not to add the twig extension (see below), defaults to true enable_twig: true
How it Works
When a request comes in, it's inspected for the Request-Id header. If present,
the value in that header will be used throughout the rest of the bundle. This
lets you use request ID's from somewhere higher up in the stack (like in the web
server itself).
If no request ID is found, one is generated by the RequestIdGenerator. The
default generator creates version 4 UUIDs.
On the way out out, the Request-Id header is set on the response as well using
the value described above.
The headers are configurable. See the configuration above.
Monolog Integration
There's a monolog Processor that adds the request ID to extra array on the
record. This can be turned off by setting enable_monolog to false in the
configuration.
To use the request ID in your logs, include %extra.request_id% in your
formatter. Here's a configuration example from this bundle's tests.
# http://symfony.com/doc/current/cookbook/logging/monolog.html#changing-the-formatter services: request_id_formatter: class: Monolog\Formatter\LineFormatter arguments: - "[%%level_name%% - %%extra.request_id%%] %%message%%" monolog: handlers: file: type: stream level: debug formatter: request_id_formatter
Twig Integration
Important: Twig ^2.7 or ^3.0 is required for the twig integration to work.
By default this bundle will add a global request_id function to your twig
environment. To disable this set enable_twig to false in the bundle
configuration.
Here's an example of a template.
<!DOCTYPE html> <html> <head> <title>Hello, World</title> </head> <body> <h1>{{ request_id() }}</h1> </body> </html>
License
MIT. See the LICENSE file.
chrisguitarguy/request-id-bundle 适用场景与选型建议
chrisguitarguy/request-id-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.47M 次下载、GitHub Stars 达 45, 最近一次更新时间为 2015 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「request id」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chrisguitarguy/request-id-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chrisguitarguy/request-id-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chrisguitarguy/request-id-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
HTTP request logger middleware for Laravel
Adds request-parameter validation to the SLIM 3.x PHP framework
Bundle Symfony DaplosBundle
A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.
Marussia request
统计信息
- 总下载量: 1.47M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 45
- 点击次数: 18
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-13