### Environment-Based Configuration Example (.env) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Illustrates how to configure the profile provider settings using environment variables in the .env file for threshold, top providers, sorting, and cache TTL. ```bash # .env file PROFILE_THRESHOLD=0.015 PROFILE_TOP_PROVIDERS=25 PROFILE_SORT_BY=memory PROFILE_CACHE_TTL=48 ``` -------------------------------- ### JSON Output Structure Example Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt An example demonstrating the structure of the JSON output generated by the profiler, including metadata, statistics, and provider-specific details. ```json { "metadata": { "timestamp": "2025-12-28T10:30:00.000000Z", "command": "profile:providers", "laravel_version": "11.0.0", "php_version": "8.2.0" }, "statistics": { "total_providers": 45, "successful_providers": 44, "failed_providers": 1, "deferred_providers": 12, "total_time": 0.456, "avg_time": 0.0101, "median_time": 0.0085, "total_memory_mb": 12.5, "avg_memory_kb": 284.5 }, "providers": { "App\\Providers\\AppServiceProvider": { "register_time": 0.0025, "boot_time": 0.0018, "total_time": 0.0043, "register_memory": 2048, "boot_memory": 1024, "total_memory": 3072, "is_deferred": false, "diagnostics": ["config", "container", "event"], "dependencies": [] } } } ``` -------------------------------- ### Example Provider with Diagnostics (PHP) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Provides an example of a problematic service provider that triggers diagnostic patterns like 'container', 'http', and 'database' due to operations in the register and boot methods. It also shows how to use deferred loading for caching. ```php app->singleton('myservice', function ($app) { return new MyService(); }); } public function boot(): void { // BAD: Will be flagged as 'http' - never do HTTP in boot // $response = Http::get('https://api.example.com/config'); // BAD: Will be flagged as 'database' - avoid queries in boot // $settings = DB::table('settings')->get(); // GOOD: Use deferred providers or lazy loading Cache::remember('settings', 3600, function () { return DB::table('settings')->get(); }); } } ``` -------------------------------- ### Continuous Monitoring Setup (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Sets up daily profiling with comparison, including memory profiling for the top 20 providers, outputting in JSON format, and exporting to a dated file. ```bash # Daily profiling with comparison php artisan profile:providers \ --compare \ --memory \ --top=20 \ --format=json \ --export=storage/profiling/daily-$(date +%Y%m%d).json ``` -------------------------------- ### Avoid N+1 Queries in Providers Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Illustrates how to prevent N+1 query problems within Laravel service providers, specifically in the `boot` method. It shows commented-out examples of inefficient eager loading and suggests using eager loading or avoiding database queries in `boot` altogether, recommending events or middleware instead. ```php load('profile'); // N+1 problem // } // GOOD: Eager loading // $users = User::with('profile')->get(); // BETTER: Don't query in boot at all // Use events or middleware instead } } ``` -------------------------------- ### Install Laravel Profile Provider Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Installs the Laravel Profile Provider package using Composer. This is a development dependency. ```bash composer require saeedvir/laravel-profile-provider --dev ``` -------------------------------- ### GitHub Actions Workflow for Profiling Providers Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt A GitHub Actions workflow file that automates the profiling of Laravel service providers. It sets up PHP, installs dependencies, runs the profiling command with specific thresholds and formats, checks for slow providers, and uploads the results as an artifact. It uses `jq` to parse JSON output. ```yaml name: Profile Providers on: pull_request: branches: [ main ] jobs: profile: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' - name: Install Dependencies run: composer install --no-interaction --prefer-dist - name: Profile Service Providers run: | php artisan profile:providers \ --threshold=0.05 \ --format=json \ --export=storage/profile-results.json - name: Check for Slow Providers run: | SLOW_COUNT=$(php artisan profile:providers --threshold=0.1 --format=json | jq '.statistics.slow_providers | length') if [ "$SLOW_COUNT" -gt 5 ]; then echo "Warning: Found $SLOW_COUNT slow providers" exit 1 fi - name: Upload Results uses: actions/upload-artifact@v3 with: name: provider-profile path: storage/profile-results.json ``` -------------------------------- ### Profile with Memory Tracking and Export Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Profiles service providers with memory tracking enabled and a threshold of 0.05 seconds, exporting the results to a specified file path. This example is useful for debugging memory-related performance issues and saving profiling data. ```bash php artisan profile:providers \ --memory \ --threshold=0.05 \ --export=storage/logs/provider-profile.json ``` -------------------------------- ### Default Laravel Profile Provider Configuration Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Example configuration for the Laravel Profile Provider, showing default values for slow provider thresholds, the number of top providers to display, sorting metrics, cache time-to-live, and maximum provider name length. ```php return [ // Default threshold in seconds for marking providers as slow 'threshold' => 0.01, // Default number of top slowest providers to display 'top' => 20, // Default field to sort providers by (total, register, boot, memory) 'sort' => 'total', // How many hours to keep previous run data for comparison 'cache_ttl_hours' => 24, // Maximum length for provider names in output tables 'max_provider_name_length' => 50, ]; ``` -------------------------------- ### GitLab CI Configuration for Profiling Providers Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt A GitLab CI configuration snippet to profile Laravel service providers. It installs dependencies, runs the profiling command, analyzes the JSON output using `jq` to check for an excessive number of slow providers, and stores the results as a job artifact. The job is configured to run on merge requests and the main branch. ```yaml profile_providers: stage: test script: - composer install --no-interaction - php artisan profile:providers --threshold=0.05 --format=json --export=profile-results.json - | SLOW_PROVIDERS=$(jq '.statistics.slow_providers | length' profile-results.json) if [ "$SLOW_PROVIDERS" -gt 10 ]; then echo "Too many slow providers detected: $SLOW_PROVIDERS" exit 1 fi artifacts: paths: - profile-results.json expire_in: 1 week only: - merge_requests - main ``` -------------------------------- ### Optimizing Application Boot Time with Parallel Estimation Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Provides a detailed analysis of application boot time by enabling parallel estimation, memory tracking, sorting by total time, and focusing on the top 10 slowest providers. This command helps in optimizing the overall application startup performance. ```bash php artisan profile:providers \ --parallel \ --memory \ --sort=total \ --top=10 ``` -------------------------------- ### Detailed Analysis with All Features Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Conducts a detailed performance analysis, including memory usage, comparison with previous runs, and parallel boot timing estimation. It sorts the results by total time and displays them in a table format, offering a comprehensive view of provider performance. ```bash php artisan profile:providers \ --memory \ --compare \ --parallel \ --sort=total \ --format=table ``` -------------------------------- ### Quick Performance Check (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Performs a quick performance check of service providers, returning the top 5 providers with a time threshold of 0.1, without diagnostics, and in JSON format. ```bash php artisan profile:providers --top=5 --threshold=0.1 --no-diagnostics --format=json ``` -------------------------------- ### Run Laravel Profile Provider (Basic) Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Executes the Laravel Profile Provider to analyze service provider performance with default settings. The output includes registration time, boot time, total time, and diagnostic information for all providers. ```bash php artisan profile:providers ``` -------------------------------- ### Complete Performance Analysis Workflow (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Executes a comprehensive performance analysis workflow for service providers, combining multiple options for detailed insights. This includes setting top providers, thresholds, memory tracking, comparison, parallel analysis, sorting, and exporting results to a dynamically named JSON file. ```bash php artisan profile:providers \ --top=15 \ --threshold=0.01 \ --memory \ --compare \ --parallel \ --sort=total \ --export=storage/profiling/analysis-$(date +%Y%m%d).json ``` -------------------------------- ### Estimate Parallel Boot Performance in Laravel Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Estimates the potential performance improvement achievable by loading service providers in parallel. This provides insights into the benefits of parallel execution for faster application startup. ```bash php artisan profile:providers --parallel ``` -------------------------------- ### Identify Parallelization Opportunities with JSON Output (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Identifies opportunities for parallelizing service provider loading and outputs the results in JSON format. This command helps in making informed decisions about implementing concurrent provider loading. ```bash php artisan profile:providers --parallel --top=10 --format=json ``` -------------------------------- ### Default Table Output Format (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Displays the profiling results in the default table format. ```bash php artisan profile:providers --format=table ``` -------------------------------- ### Monitor Top Providers with Comparison Settings (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Monitors the top service providers while comparing current performance with previous runs, using specific thresholds. This allows for focused analysis on critical providers and performance changes. ```bash php artisan profile:providers --compare --top=20 --threshold=0.01 ``` -------------------------------- ### Focus on Slow Providers with Diagnostics (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Profiles service providers, focusing on those exceeding a specific threshold, and includes diagnostic analysis. This command helps in quickly identifying and analyzing the performance issues of the slowest providers. ```bash php artisan profile:providers --threshold=0.1 --top=5 ``` -------------------------------- ### Parallel Analysis with Full Metrics (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Performs a parallel provider loading analysis including memory usage and comparison data. This provides a comprehensive view of performance under concurrent loading conditions. ```bash php artisan profile:providers --parallel --memory --compare ``` -------------------------------- ### Compare Cached vs Non-Cached Provider Performance (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Compares the performance of service providers when loaded from cache versus when loaded normally. This involves running two separate profiling commands and comparing their outputs. ```bash # First run with cache php artisan profile:providers --only-cached --export=storage/cached-results.json # Then run without cache php artisan profile:providers --export=storage/full-results.json ``` -------------------------------- ### Complete Performance Analysis with Export Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Performs a comprehensive performance analysis of service providers, including memory tracking, comparison with previous runs, parallel estimation, and exports the results to a JSON file. This command is useful for detailed performance audits and historical tracking. ```bash php artisan profile:providers \ --top=15 \ --threshold=0.01 \ --memory \ --compare \ --parallel \ --export=storage/profiling/analysis-$(date +%Y%m%d).json ``` -------------------------------- ### Full Diagnostic Analysis with Memory Tracking (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Performs a full diagnostic analysis of service providers, including memory tracking. This command provides deep insights into provider performance and resource consumption. ```bash php artisan profile:providers --memory --top=20 ``` -------------------------------- ### Complete Memory Analysis with Top Consumers (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Performs a complete memory analysis of service providers, displaying the top consumers. This provides a detailed view of memory usage and helps identify optimization opportunities. ```bash php artisan profile:providers --memory --top=15 --sort=memory ``` -------------------------------- ### Custom Configuration File (PHP) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Shows a typical configuration file for the profile-provider package, allowing customization of threshold, top providers, sorting, cache TTL, and maximum provider name length via environment variables. ```php // config/profile-provider.php return [ 'threshold' => env('PROFILE_THRESHOLD', 0.01), 'top' => env('PROFILE_TOP_PROVIDERS', 20), 'sort' => env('PROFILE_SORT_BY', 'total'), 'cache_ttl_hours' => env('PROFILE_CACHE_TTL', 24), 'max_provider_name_length' => 50, ]; ``` -------------------------------- ### Quick Check for Slow Providers Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Quickly identifies the top 5 slowest service providers that exceed a threshold of 0.1 seconds, without performing detailed diagnostics. This is ideal for a rapid assessment of performance bottlenecks. ```bash php artisan profile:providers --top=5 --threshold=0.1 --no-diagnostics ``` -------------------------------- ### JSON Output Format (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Outputs the profiling results in JSON format, suitable for programmatic consumption. ```bash php artisan profile:providers --format=json ``` -------------------------------- ### Detailed Memory Profiling (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Conducts a detailed memory profiling of service providers, sorting by memory usage, listing the top 25, and exporting the results to a CSV file. ```bash php artisan profile:providers \ --memory \ --sort=memory \ --top=25 \ --export=storage/memory-analysis.csv ``` -------------------------------- ### Profile Service Providers Sorted by Metric (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Profiles service providers and sorts the output based on a specified metric such as registration time, boot time, total time, or memory. This helps in analyzing specific performance aspects. ```bash # Sort by registration time php artisan profile:providers --sort=register # Sort by boot time php artisan profile:providers --sort=boot # Sort by total time (default) php artisan profile:providers --sort=total ``` -------------------------------- ### Perform Dry Run of Laravel Provider Profiling Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Simulates the service provider profiling process without actually executing the providers' registration and boot methods. This is useful for testing the profiler's functionality and configuration. ```bash php artisan profile:providers --dry-run ``` -------------------------------- ### CSV Output Format (CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Outputs the profiling results in CSV format, ideal for analysis in spreadsheet software. ```bash php artisan profile:providers --format=csv ``` -------------------------------- ### Track Memory Performance Changes Over Time (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Compares the current memory usage of service providers with previous runs. This helps in monitoring memory trends and identifying any increases or decreases in consumption. ```bash php artisan profile:providers --compare --memory ``` -------------------------------- ### Export Complete Analysis with Dynamic Filename (Bash) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Exports a comprehensive profiling analysis, including memory and comparison data, to a JSON file with a dynamically generated filename based on the current date and time. This is useful for creating historical performance records. ```bash php artisan profile:providers \ --memory \ --compare \ --format=json \ --export=storage/profiling/analysis-$(date +%Y%m%d-%H%M%S).json ``` -------------------------------- ### Compare Laravel Provider Performance Over Time Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Compares the current service provider performance metrics with previous profiling runs. This feature is useful for tracking performance regressions or improvements over time. ```bash php artisan profile:providers --compare ``` -------------------------------- ### Sort Laravel Providers by Boot Time Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Sorts the service provider profiling results by their boot time, enabling identification of providers that are slow during the application boot sequence. ```bash php artisan profile:providers --sort=boot ``` -------------------------------- ### Optimize Provider Loading - DeferrableProvider Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Demonstrates how to make a Laravel service provider deferrable, meaning it will only be loaded when its services are actually needed. This improves initial application boot time by avoiding unnecessary service instantiation. It implements the `DeferrableProvider` interface and the `provides` method. ```php app->singleton(HeavyService::class, function ($app) { return new HeavyService($app['config']); }); } } // AFTER: Deferred provider - only loaded when needed class HeavyServiceProvider extends ServiceProvider implements DeferrableProvider { public function register(): void { $this->app->singleton(HeavyService::class, function ($app) { return new HeavyService($app['config']); }); } public function provides(): array { return [HeavyService::class]; } } ``` -------------------------------- ### Continuous Performance Monitoring with Comparison Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Monitors application performance by comparing the current provider profiling results with previous runs, focusing on the top 20 slowest providers and including memory tracking. This helps in identifying performance regressions over time. ```bash php artisan profile:providers \ --compare \ --top=20 \ --memory ``` -------------------------------- ### Find Slowest Laravel Providers Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Identifies and displays the top N slowest service providers based on their performance metrics. This helps pinpoint performance bottlenecks in the application's boot process. ```bash php artisan profile:providers --top=10 ``` -------------------------------- ### Test Export Functionality (Dry Run - CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Tests the export functionality in dry run mode, simulating the creation of a JSON output file. ```bash php artisan profile:providers --dry-run --format=json --export=storage/test.json ``` -------------------------------- ### Debugging Specific Performance Issues with JSON Output Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Filters service providers that have database operations in their diagnostics, using JSON output format and `jq` for processing. This is useful for pinpointing providers that might be causing database-related performance bottlenecks. ```bash php artisan profile:providers \ --memory \ --format=json | jq '.providers | to_entries[] | select(.value.diagnostics | contains(["database"]))' ``` -------------------------------- ### Validate Command Options (Dry Run - CLI) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Validates various command options such as memory profiling, comparison, and parallel execution in dry run mode. ```bash php artisan profile:providers --dry-run --memory --compare --parallel ``` -------------------------------- ### Publish Laravel Profile Provider Configuration Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Publishes the configuration file for the Laravel Profile Provider package, allowing customization of profiling settings such as thresholds, sorting, and cache duration. ```bash php artisan vendor:publish --provider="Saeedvir\LaravelProfileProvider\LaravelProfileProviderServiceProvider" ``` -------------------------------- ### Service Provider Registration (PHP) Source: https://context7.com/saeedvir/laravelprofileprovider/llms.txt Demonstrates how the LaravelProfileProviderServiceProvider auto-registers, and how to conditionally merge custom configuration in the application's AppServiceProvider. ```php environment('local', 'testing')) { config([ 'profile-provider.threshold' => 0.005, 'profile-provider.top' => 30, ]); } } public function boot(): void { // Provider boot logic } } ``` -------------------------------- ### Export Laravel Provider Profiling Results (JSON) Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Exports the detailed service provider profiling results to a JSON file. This allows for further programmatic analysis or integration with other tools. ```bash php artisan profile:providers --format=json --export=storage/profiling/results.json ``` -------------------------------- ### Sort Laravel Providers by Registration Time Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Sorts the service provider profiling results by their registration time, allowing analysis of the slowest providers during the registration phase. ```bash php artisan profile:providers --sort=register ``` -------------------------------- ### Sort Laravel Providers by Memory Usage Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Sorts the service provider profiling results by memory usage, helping to identify providers with high memory consumption. Requires the `--memory` flag to be enabled. ```bash php artisan profile:providers --sort=memory --memory ``` -------------------------------- ### Skip Diagnostics in Laravel Provider Profiling Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Performs service provider profiling without running the diagnostic analysis. This can speed up the profiling process when detailed diagnostic checks are not required. ```bash php artisan profile:providers --no-diagnostics ``` -------------------------------- ### Track Memory Usage in Laravel Providers Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Includes memory consumption analysis in the service provider profiling results. This helps identify providers that consume excessive memory during registration or booting. ```bash php artisan profile:providers --memory ``` -------------------------------- ### Filter Laravel Providers by Threshold Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Filters the profiling results to display only service providers that exceed a specified performance threshold (in seconds). This helps focus on the most critical performance issues. ```bash php artisan profile:providers --threshold=0.05 ``` -------------------------------- ### Export Laravel Provider Profiling Results (CSV) Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Exports the detailed service provider profiling results to a CSV file. This format is easily importable into spreadsheet software for analysis. ```bash php artisan profile:providers --format=csv --export=storage/profiling/results.csv ``` -------------------------------- ### Profile Only Cached Laravel Providers Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Exclusively profiles service providers that are part of the bootstrap cache, ignoring any non-cached providers. This focuses the analysis on the performance of already cached components. ```bash php artisan profile:providers --only-cached ``` -------------------------------- ### Profile Cached Providers in Laravel Source: https://github.com/saeedvir/laravelprofileprovider/blob/main/README.md Profiles only the service providers that are included in the application's bootstrap cache. This can be useful for analyzing the performance of cached providers specifically. ```bash php artisan profile:providers --use-cache ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.