maantje / xhprof-buggregator-laravel by moijamie

Xhprof buggregator integration for Laravel
52,501
31
3
Package Data
Maintainer Username: moijamie
Maintainer Contact: j4mie@hey.com (Jamie Schouten)
Package Create Date: 2023-10-17
Package Last Update: 2025-01-27
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2025-01-31 15:00:02
Package Statistics
Total Downloads: 52,501
Monthly Downloads: 11,240
Daily Downloads: 743
Total Stars: 31
Total Watchers: 3
Total Forks: 7
Total Open Issues: 0

Xhprof support in buggregator for Laravel

Welcome to the Xhprof integration package for buggregator in Laravel. This repository allows you to effortlessly enable Xhprof support for buggregator in your Laravel application.

Requirements

Make sure that your server is configured with following PHP version and extensions:

Installation

To get started, install the package via composer:

composer require --dev maantje/xhprof-buggregator-laravel

Usage

Set the buggregator endpoint in your environment file, the displayed value is the default value:

PROFILER_ENDPOINT=http://127.0.0.1:8000/api/profiler/store

Toggle Xhprof in your environment file as needed, but remember to disable it when not in use to avoid performance impact

XHPROF_ENABLED=true

Alternatively, you can include the X-Xhprof-Enabled header in your request to explicitly enable or disable profiling for that specific call. When this header is present, it takes precedence over the environment variable.

Enabled values: true 1 on yes
Disabled values: false 0 off no

This feature works great with a browser extension like ModHeader. It lets you switch profiling on and off right from your browser.

Usage Profiler

By default, the profiler is turned on and off with each HTTP request. However, you may have other points where your\application starts. For example, it can be queues, commands, and so on.

In such cases, you can configure the profiler to run in the desired location yourself:


use SpiralPackages\Profiler\Profiler;

class RegisterUserActionJob 
{
    public function __construct(
        public string $name,
        public string $password
    ) {
    }
    
    /**
     * Get Profiler object from Container DI
     * 
     * @param Profiler $profiler
     * @return void
     */
    public function handle(Profiler $profiler): void
    {
        try {
            $profiler->start();
            
            // code for register new user
        }
        finally {
            $profiler->end();
        }
    }
}

Usage with Sail

Add the buggregator service to your docker-compose file:

buggregator:
    image: ghcr.io/buggregator/server:dev
    ports:
        - 8000:8000
        - 1025:1025
        - 9912:9912
        - 9913:9913
    networks:
        - sail

Set the profiler endpoint in your environment file:

PROFILER_ENDPOINT=http://buggregator:8000/api/profiler/store

License

The MIT License (MIT). Please see License File for more information.