{"id":43160297,"url":"https://github.com/verbanent/laravel-sql-performance-guard","last_synced_at":"2026-02-01T01:17:12.246Z","repository":{"id":63632346,"uuid":"569373890","full_name":"verbanent/laravel-sql-performance-guard","owner":"verbanent","description":"A service provider to monitor SQL statements, check the performance (EXPLAIN command), view real-time queries, and collect SQL logs to optimise them.","archived":false,"fork":false,"pushed_at":"2023-03-26T19:56:51.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-14T07:34:05.362Z","etag":null,"topics":["explain","laravel","laravel-package","laravel-provider","optimisation","performance","provider","queries","sql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/verbanent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-11-22T17:20:46.000Z","updated_at":"2022-12-15T06:49:52.000Z","dependencies_parsed_at":"2023-09-30T07:16:53.753Z","dependency_job_id":null,"html_url":"https://github.com/verbanent/laravel-sql-performance-guard","commit_stats":{"total_commits":12,"total_committers":2,"mean_commits":6.0,"dds":0.08333333333333337,"last_synced_commit":"e63883954f86ab566b60dfb1222c8825e47865d3"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/verbanent/laravel-sql-performance-guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/verbanent%2Flaravel-sql-performance-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/verbanent%2Flaravel-sql-performance-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/verbanent%2Flaravel-sql-performance-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/verbanent%2Flaravel-sql-performance-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/verbanent","download_url":"https://codeload.github.com/verbanent/laravel-sql-performance-guard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/verbanent%2Flaravel-sql-performance-guard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28963439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T00:42:38.011Z","status":"ssl_error","status_checked_at":"2026-02-01T00:42:35.920Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["explain","laravel","laravel-package","laravel-provider","optimisation","performance","provider","queries","sql"],"created_at":"2026-02-01T01:17:11.758Z","updated_at":"2026-02-01T01:17:12.240Z","avatar_url":"https://github.com/verbanent.png","language":"PHP","readme":"# Laravel SQL Performance Guard\n\nA service provider to monitor SQL statements, check the performance (EXPLAIN command), view real-time queries, and collect SQL logs to optimise them.\n\n## Installation\n\nPlease install the package via Composer:\n\n```shell\ncomposer require verbanent/laravel-sql-performance-guard\n```\n\nYou can publish the config file if you need to change its default values:\n\n```shell\nphp artisan vendor:publish --provider=\"Verbanent\\SqlPerformanceGuard\\SqlPerformanceGuardServiceProvider\" --tag=\"config\"\n```\n\nDefault settings:\n\n```php\n\u003c?php\n\nreturn [\n    'time_threshold' =\u003e env('SQL_TIME_THRESHOLD', 100.00),\n    'key_length_threshold' =\u003e env('SQL_KEY_LENGTH_THRESHOLD', 256),\n    'rows_threshold' =\u003e env('SQL_ROWS_THRESHOLD', 1000),\n];\n```\n\n## Usage\n\nCurrently, the library works only in the debug mode. Please run it in your development\nenvironment to test SQL queries and make required amends to improve the SQL performance.\nIf you see better results, apply these changes to your Production environment.\n\n## Example\n\nInstall a package and check your logs:\n\n```shell\ntail -f storage/logs/laravel.log\n```\n\nChange your application mode to `DEBUG` by updating your `.env` file:\n\n```shell\nAPP_ENV=local\nAPP_DEBUG=true\nLOG_CHANNEL=single\nLOG_LEVEL=debug\n```\n\nIt's just an example. If you configured your logs you might not need to do any changes here. \n\nOpen a page or run a CLI command to trigger saving debug logs. You should something like this:\n\n```shell\n=============== EXPLAIN BEGIN ===============\nSQL {\"sql\":\"select * from `users` where `email` = 'example@example.com' limit 1\"}\n\nTABLE 1: users {\"id\":1,\"select_type\":\"SIMPLE\",\"table\":\"users\",\"partitions\":null,\"type\":\"ALL\",\"possible_keys\":null,\"key\":null,\"key_len\":null,\"ref\":null,\"rows\":83289,\"filtered\":10.0,\"Extra\":\"Using where\"}\nPASSED: TIME {\"time \u003c 100.00\":66.73}\nWARNING: POSSIBLE KEYS {\"possible keys are null\":null}\nWARNING: KEY {\"key is null\":null}\nWARNING: KEY LEN {\"key len is null\":null}\nWARNING: KEY LEN VALUE {\"key len \u003e= 256\":null}\nWARNING: ROWS {\"rows \u003e= 1000\":83289}\n=============== EXPLAIN = END ===============\n```\n\nWe see the problem is that the query doesn't use any indexes (keys) to filter results. It means it must go through more than 80.000 rows to get the results.\n\nBased on this knowledge let's optimise our table `users` by adding an index:\n\n```sql\ncreate index email_idx on users (email)\n```\n\nIt's better know:\n\n```shell\n=============== EXPLAIN BEGIN ===============\nSQL {\"sql\":\"select * from `users` where `email` = 'example@example.com' limit 1\"}\n\nTABLE 1: users {\"id\":1,\"select_type\":\"SIMPLE\",\"table\":\"users\",\"partitions\":null,\"type\":\"ref\",\"possible_keys\":\"email_idx\",\"key\":\"email_idx\",\"key_len\":\"515\",\"ref\":\"const\",\"rows\":1,\"filtered\":100.0,\"Extra\":null}\nPASSED: TIME {\"time \u003c 100.00\":17.88}\nPASSED: POSSIBLE KEYS {\"possible keys exist\":\"email_idx\"}\nPASSED: KEY {\"key chosen\":\"email_idx\"}\nPASSED: KEY LEN {\"key len is not null\":\"515\"}\nWARNING: KEY LEN VALUE {\"key len \u003e= 256\":\"515\"}\nPASSED: ROWS {\"rows \u003c 1000\":1}\n=============== EXPLAIN = END ===============\n```\n\nBut still not perfect. There's the last warning related to the key length. It means that the column contains longer strings and our index might be huge if we don't limit it. Let's try to fix it based on that information:\n\n```sql\ndrop index email_idx on users;\ncreate index email_idx on users (email(32));\n```\n\nThe results show all tests passed:\n\n```shell\n=============== EXPLAIN BEGIN ===============\nSQL {\"sql\":\"select * from `users` where `email` = 'example@example.com' limit 1\"}\n\nTABLE 1: users {\"id\":1,\"select_type\":\"SIMPLE\",\"table\":\"users\",\"partitions\":null,\"type\":\"ref\",\"possible_keys\":\"email_idx\",\"key\":\"email_idx\",\"key_len\":\"131\",\"ref\":\"const\",\"rows\":1,\"filtered\":100.0,\"Extra\":\"Using where\"}\nPASSED: TIME {\"time \u003c 100.00\":14.31}\nPASSED: POSSIBLE KEYS {\"possible keys exist\":\"email_idx\"}\nPASSED: KEY {\"key chosen\":\"email_idx\"}\nPASSED: KEY LEN {\"key len is not null\":\"131\"}\nPASSED: KEY LEN VALUE {\"key len \u003c 256\":\"131\"}\nPASSED: ROWS {\"rows \u003c 1000\":1}\n=============== EXPLAIN = END ===============\n```\n\nThis is a simple tool to help you diagnose the issue with your queries based on the `EXPLAIN` command. It should be used during your developing process. We don't recommend running it in your Production environment.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverbanent%2Flaravel-sql-performance-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fverbanent%2Flaravel-sql-performance-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fverbanent%2Flaravel-sql-performance-guard/lists"}