simple-as-fuck/php-performance-log

There is no license information available for the latest version (0.5.0) of this package.

Services for logging slow parts of application.

Installs: 48

Dependents: 1

Suggesters: 1

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/simple-as-fuck/php-performance-log

0.5.0 2025-08-30 19:52 UTC

This package is auto-updated.

Last update: 2025-09-30 20:42:05 UTC


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

Application Http requests DB transactions SQL queries Console commands Queue Jobs
Laravel With middleware use default 1 second Default 300 milliseconds Default 50 milliseconds Default off Recommended 40 seconds

Laravel application

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

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

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

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 request time logging you must register PsrMiddleware. Recommended usage is register middleware as global on first position and all of your 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

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->setSlowRequestThreshold(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.