simple-as-fuck/php-performance-log 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simple-as-fuck/php-performance-log

Composer 安装命令:

composer require simple-as-fuck/php-performance-log

包简介

Services for logging slow parts of application.

README 文档

README

Services for logging slow parts of application.

Installation

composer require simple-as-fuck/php-performance-log

Support

If any PHP platform requirements in composer.json ends with security support, consider package version as unsupported except last version.

PHP supported versions.

Measurements support

Tools Http server requests Http client requests DB transactions SQL queries Console commands Queue Jobs
Laravel With middleware use, default 1 second Guzzle with handler stack build by Laravel, default 700 milliseconds Default 300 milliseconds Default 50 milliseconds Default off Recommended 40 seconds
Guzzle Unsupported With middleware use, default 700 milliseconds Unsupported Unsupported Unsupported Unsupported

Laravel application

Global thresholds configuration are in performance_log.php config, publishable from package.

php artisan vendor:publish --tag performance-log-config

For http server request time logging you must register LaravelMiddleware as global on first position.

Application with Guzzle

For http client request time logging you must register GuzzleMiddleware to your guzzle instance.

Other applications

All package services or listeners do not have any external dependencies except PSR interfaces, is possible use package for measurement of different types of applications.

You must register some PerformanceLogConfig extends to your application as unique global instance (singleton), because in the service state are hold temporary thresholds overwrites, and you should overwrite methods getConfig..., where you can configure your global thresholds or in methods load thresholds from application configuration files.

Thresholds values has behaviour: not zero value will log longer runs then threshold value as warning, null or zero value turn off measurement, zero value with debug true will log running time as debug.

You can look at LaravelPerformanceLogConfig as example.

You must register listeners to your application as singletons, because most listeners has state and hold measurements data inside. PSR-14 listeners are callables, you can register package listeners by anonymous function adapters.

You can look at LaravelProvider as example.

For http server request time logging you must register PsrMiddleware. Recommended usage is register middleware as global on first position and all of your server request will be measured.

Thresholds overwrite

Sql

If you know than some sql is slow, and you are fine with that you can overwrite global thresholds configuration by setting a temporary threshold in PerformanceLogConfig.

/** @var \SimpleAsFuck\PerformanceLog\Service\PerformanceLogConfig $performanceLogConfig */

$sqlThreshold = $performanceLogConfig->setSlowSqlQueryThreshold(null);
$transactionThreshold = $performanceLogConfig->setSlowDbTransactionThreshold(null);

// run some slow queries without annoying performance log

$sqlThreshold->restore();
$transactionThreshold->restore();

Http client

If you know that some webservice is slow or some your microservice dependency should be extra fast, you can overwrite global threshold configuration by setting a temporary threshold.

/** @var \SimpleAsFuck\PerformanceLog\Service\PerformanceLogConfig $performanceLogConfig */

$requestThreshold = $performanceLogConfig->setSlowClientRequestThreshold(null);

// call http requests by your client

$requestThreshold->restore();

Http server

If you know that some specific controller action is slow or should be extra fast, you can overwrite global threshold configuration by setting a temporary threshold. The temporary threshold can be set anywhere in request run and live until a request ends.

/** @var \SimpleAsFuck\PerformanceLog\Service\PerformanceLogConfig $performanceLogConfig */

$performanceLogConfig->setSlowServerRequestThreshold(null);

// run some extra slow logic without annoying performance log

// no need for threshold restoring, performance listener will handle it

Console

If you want to overwrite global threshold configuration, you can do it by setting a temporary threshold. The temporary threshold can be set anywhere in command run and live until a command ends.

/** @var \SimpleAsFuck\PerformanceLog\Service\PerformanceLogConfig $performanceLogConfig */

$performanceLogConfig->setSlowCommandThreshold(60); // one minute

// run some measured logic

// no need for threshold restoring, performance listener will handle it

Job

If you want to overwrite global threshold configuration, you can set a temporary threshold. The temporary threshold can be set anywhere in job run and live until a job ends.

/** @var \SimpleAsFuck\PerformanceLog\Service\PerformanceLogConfig $performanceLogConfig */

$performanceLogConfig->setSlowJobThreshold(10000); // 10 seconds

// run some measured logic

// no need for threshold restoring, performance listener will handle it

Usage with monitoring

Is recommended send performance warning logs into your monitoring system, so you know what is slow.

For simple monitoring is sentry integration. Sentry integration can collect information about request or command with stacktrace, this can make finding slow query much easier.

统计信息

  • 总下载量: 739
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unlicense
  • 更新时间: 2025-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固