barbushin/swoole-blackfire
Composer 安装命令:
composer require barbushin/swoole-blackfire
包简介
Blackfire profiler for PHP applications running on Swoole web-server
README 文档
README
This library enables profiling of PHP applications running on Swoole web-server via Blackfire.
Features:
- Transparent request profiling
- Selective sub-system profiling
- Custom start/stop profiling calls
- Blackfire Companion integration
Installation
The library is to be installed via Composer as a dev dependency:
composer require upscale/swoole-blackfire --dev
Usage
Request Profiling
The easiest way to start profiling is to activate the profiler globally for all requests from start to finish. This approach is by design completely transparent to an application running on the server. No code changes are needed beyond editing a few lines of code in the server entry point.
Activate profiling of all requests using one of the following methods:
- Wrap the server middleware in the profiler decorator:
$profiler = new \Upscale\Swoole\Blackfire\Profiler(); $server->on('request', $profiler->wrap(function ($request, $response) { $response->header('Content-Type', 'text/plain'); $response->end( 'CRC32: ' . hash_file('crc32b', __FILE__) . "\n" . 'MD5: ' . md5_file(__FILE__) . "\n" . 'SHA1: ' . sha1_file(__FILE__) . "\n" ); }));
- Or, install the profiler instrumentation retroactively:
$server->on('request', function ($request, $response) { $response->header('Content-Type', 'text/plain'); $response->end( 'CRC32: ' . hash_file('crc32b', __FILE__) . "\n" . 'MD5: ' . md5_file(__FILE__) . "\n" . 'SHA1: ' . sha1_file(__FILE__) . "\n" ); }); $profiler = new \Upscale\Swoole\Blackfire\Profiler(); $profiler->instrument($server);
Selective Profiling
It is possible to limit the profiling scope by wrapping the interested code in a profiler call.
Wrap the code intended to be profiled in the profiler call:
$profiler = new \Upscale\Swoole\Blackfire\Profiler(); $server->on('request', function ($request, $response) use ($profiler) { $response->header('Content-Type', 'text/plain'); $profiler->inspect($request, $response, function ($request, $response) { $response->write('CRC32: ' . hash_file('crc32b', __FILE__) . "\n"); }); $response->write('MD5: ' . md5_file(__FILE__) . "\n"); $response->write('SHA1: ' . sha1_file(__FILE__) . "\n"); });
Currently, only one profiler inspection call is permitted per request.
Manual Profiling
Depending on the application design and complexity, it may be difficult to precisely wrap desired code in the profiler call. Profiler start/stop calls can be manually placed at different call stack levels to further narrow down the inspection scope. With this approach, a developer must guarantee the symmetry of the calls and consider the response population workflow. The profiling must be stopped before sending the response body to be able to send the results in the response headers.
Surround the code intended to be profiled with the profiler start/stop calls:
$profiler = new \Upscale\Swoole\Blackfire\Profiler(); $server->on('request', function ($request, $response) use ($profiler) { $response->header('Content-Type', 'text/plain'); $output = 'CRC32: ' . hash_file('crc32b', __FILE__) . "\n"; $profiler->start($request); $output .= 'MD5: ' . md5_file(__FILE__) . "\n"; $profiler->stop($request, $response); $output .= 'SHA1: ' . sha1_file(__FILE__) . "\n" $response->end($output); });
Currently, only one pair of the profiler start/stop calls is permitted per request.
Limitations
The profiling implicitly stops before sending the response body and the results are added to the response headers.
Currently, only one profiling session initiated by inspect() or start/stop() calls is supported per request.
Contributing
Pull Requests with fixes and improvements are welcome!
License
Copyright © Upscale Software. All rights reserved.
Licensed under the Apache License, Version 2.0.
barbushin/swoole-blackfire 适用场景与选型建议
barbushin/swoole-blackfire 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「profiler」 「profiling」 「swoole」 「blackfire」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 barbushin/swoole-blackfire 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 barbushin/swoole-blackfire 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 barbushin/swoole-blackfire 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Quick profiling of your code for Laravel
g4 application profiler package
Excimetry PHP package. Bridge between ext-eximer and open telemetry
An SDK for sending profiling data to Perfbase
MongoQP is a frontend for MongoDB's query profiler collection.
annotations-scan-plugin
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-03-21