PHP code example of padosoft / laravel-querymonitor

1. Go to this page and download the library: Download padosoft/laravel-querymonitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

padosoft / laravel-querymonitor example snippets


return [

    'query' => [
        'attiva' => env('QUERYMONITOR_QUERY_ATTIVA', true),
        'maxExecutionTime' => env('QUERYMONITOR_QUERY_MAX_EXECUTION_TIME', 100), // in milliseconds
        'sqlRegEx' => env('QUERYMONITOR_QUERY_SQL_REGEX', '^SELECT.*$'),
    ],

    'query_builder' => [
        'attiva' => env('QUERYMONITOR_BUILDER_ATTIVA', true),
        'maxExecutionTime' => env('QUERYMONITOR_BUILDER_MAX_EXECUTION_TIME', 200), // in milliseconds
        'methodRegEx' => env('QUERYMONITOR_BUILDER_METHOD_REGEX', '^(get|first)$'),
    ],

    'total_queries' => [
    
        /*
         * Whether to enable total query monitoring.
         */
        'attiva' => env('QUERYMONITOR_TOTAL_QUERIES_ATTIVA', true),
    
        /*
         * Maximum allowed total queries per request/command.
         * If this threshold is exceeded, a warning is logged.
         */
        'maxTotalQueries' => env('QUERYMONITOR_MAX_TOTAL_QUERIES', 500),
    
        /*
         * A regex to filter which contexts to monitor.
         * - For HTTP requests, this regex will be matched against the full URL (including query string).
         * - For Artisan commands, it will be matched against the command name.
         * - For CLI contexts, it can be matched against the script name.
         * If unset or empty, all contexts are monitored.
         * Example: '^/api/.*$' to monitor only requests under /api/
         */
        'traceRegEx' => env('QUERYMONITOR_TOTAL_QUERIES_REGEX', null),
    ],
];

$users = User::all();

'total_queries' => [

    /*
     * Whether to enable total query monitoring.
     */
    'attiva' => env('QUERYMONITOR_TOTAL_QUERIES_ATTIVA', true),

    /*
     * Maximum allowed total queries per request/command.
     * If this threshold is exceeded, a warning is logged.
     */
    'maxTotalQueries' => env('QUERYMONITOR_MAX_TOTAL_QUERIES', 500),

    /*
     * A regex to filter which contexts to monitor.
     * - For HTTP requests, this regex will be matched against the full URL (including query string).
     * - For Artisan commands, it will be matched against the command name.
     * - For CLI contexts, it can be matched against the script name.
     * If unset or empty, all contexts are monitored.
     * Example: '^/api/.*$' to monitor only requests under /api/
     */
    'traceRegEx' => env('QUERYMONITOR_TOTAL_QUERIES_REGEX', null),
],

protected $middleware = [
                        \Padosoft\QueryMonitor\Middleware\TrackTotalQueriesMiddleware::class,
                        // ... other global middleware ...
                        ];

'traceRegEx' => '^/api/.*$',
bash
php artisan vendor:publish --provider="Padosoft\QueryMonitor\QueryMonitorServiceProvider" --tag="config"