Skip to content

Commit

Permalink
Add option to disable middleware. When we try to profile some part of…
Browse files Browse the repository at this point in the history
… code.
  • Loading branch information
Artur Melikbekian authored and Artur Melikbekian committed Jul 9, 2024
1 parent b1f44d9 commit 65b7264
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/xhprof.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

return [
'enabled' => (bool) env('XHPROF_ENABLED', false),
'on_startup' => (bool) env('XHPROF_ON_STARTUP', true),
'register_middleware' => (bool) env('XHPROF_REGISTER_MIDDLEWARE', true),
'endpoint' => (string) env('PROFILER_ENDPOINT', 'http://127.0.0.1:8000/api/profiler/store'),
];
9 changes: 4 additions & 5 deletions src/XhprofServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public function register(): void
return;
}

if ($this->onStartup()) {
if ($this->canRegisterMiddleware()) {
$this->registerMiddleware();
}


$this->app->bind(Profiler::class, function () {
$storage = new WebStorage(
new CurlHttpClient(),
Expand Down Expand Up @@ -86,12 +85,12 @@ private function isEnabled(): bool
}
}

private function onStartup(): bool
private function canRegisterMiddleware(): bool
{
try {
return config()->get('xhprof.on_startup');
return config()->get('xhprof.register_middleware');
} catch (Throwable) {
return false;
return true;
}
}
}

0 comments on commit 65b7264

Please sign in to comment.