PHP code example of yorcreative / laravel-query-watcher
1. Go to this page and download the library: Download yorcreative/laravel-query-watcher 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/ */
yorcreative / laravel-query-watcher example snippets
[
// Do you want to capture queries?
'enabled' => env('QUERY_WATCH_ENABLED', true),
// Token used for Authenticating Private Broadcast Channel
'token' => env('QUERY_WATCH_TOKEN', 'change_me'),
'scope' => [
'time_exceeds_ms' => [
// Do you want to capture everything or only slow queries?
'enabled' => env('QUERY_WATCH_SCOPE_TIME_ENABLED', true),
// The number of milliseconds it took to execute the query.
'threshold' => env('QUERY_WATCH_SCOPE_TIME_THRESHOLD', 500),
],
'context' => [
'auth_user' => [
// Do you want to know context of the authenticated user when query is captured?
'enabled' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_ENABLED', true),
// How long do you want the session_id/authenticated user cached for?
// without this cache, your application will infinite loop because it will capture
// the user query and loop.
// See closed Issue #1 for context.
'ttl' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_TTL', 300),
],
'trigger' => [
// Do you want to know what triggered the query?
// i.e Console command or Request
'enabled' => env('QUERY_WATCH_SCOPE_TRIGGER_ENABLED', true),
],
],
'ignorable_tables' => [
// Do you want to capture queries on specific tables?
// If you are utilizing the database queue driver, you need to
// ignore the jobs table, or you'll potentially get infinite capture loops.
'jobs',
'failed_jobs'
],
'ignorable_statements' => [
// Do you want to ignore specific SQL statements?
'create'
]
],
'listener' => [
// Channel notifications are queued
// Define what connection to use.
'connection' => 'sync',
// Define what queue to use
'queue' => 'default',
// Do you want to delay the notifications at all?
'delay' => null,
],
'channels' => [ // Where to send notifications?
'discord' => [
// Do you want discord webhook notifications?
'enabled' => env('QUERY_WATCH_CHANNEL_DISCORD_ENABLED', false),
// Discord Web-hook URL
'hook' => env('DISCORD_HOOK', 'please_fill_me_in'),
],
'slack' => [
// Do you want Slack webhook notifications?
'enabled' => env('QUERY_WATCH_CHANNEL_SLACK_ENABLED', false),
// Slack Web-hook URL
'hook' => env('SLACK_HOOK', 'please_fill_me_in'),
],
]
]
/**
* Get the channels the event should broadcast on.
*
* @return PrivateChannel
*/
public function broadcastOn(): PrivateChannel
{
return new PrivateChannel('query.event.'. config('querywatcher.token'));
}
/**
* @return string
*/
public function broadcastAs(): string
{
return 'query.event';
}