emteknetnz / silverstripe-db-query-counter
A SilverStripe module for query counting.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- silverstripe/framework: ^5 || ^6
This package is auto-updated.
Last update: 2025-04-24 03:49:34 UTC
README
This is a SilverStripe module for counting the number of database queries made.
Installation
composer require emteknetnz/silverstripe-db-query-counter
And then flush.
Usage
Add ?log=1
to the URL to enable query logging for the current request, including any sub XHR requests. This will redirect to ?log=0
after 3 seconds.
To change the number of seconds before the redirect:
emteknetnz\DBQueryCounter\DBQueryMiddleware: redirect_seconds: 5
By default two files queries.txt
and queries-trace.txt
will be written to a db-query-counter
subdirectory in the system temporary directory. To change where these files are written:
emteknetnz\DBQueryCounter\DBQueryLogger: logfile: /path/to/queries.txt logfile_trace: /path/to/queries-trace.txt
Aftet the automatic redirect to ?log=0
, by default two files report.txt
and report-trace.txt
will be written to a db-query-counter
subdirectory in the system temporary directory. To change where these files are written:
emteknetnz\DBQueryCounter\DBQueryReportWriter: outfile: /path/to/report.txt outfile_trace: /path/to/report-trace.txt
To help find out what triggered the DB query, report-trace.txt
file include a stack trace of callees, with common core classes such as ORM classes filtered out. By default this will be done to a depth of 10, though this is configurable, which can be useful for grouping similar queries. Note this has no impact on performance, only on what's reported:
emteknetnz\DBQueryCounter\DBQueryLogger: trace_depth: 3
Notes
- A
DBQueryMySQLiConnector
class is injected in to replaceMySQLiConnector
to allow for logging database queries. If you have a custom connector, you will need to extend this class instead ofMySQLiConnector
.