https://github.com/phpfui/mysqlslowqueryparser
PHP MySQL Slow Query Parser
https://github.com/phpfui/mysqlslowqueryparser
Last synced: 6 days ago
JSON representation
PHP MySQL Slow Query Parser
- Host: GitHub
- URL: https://github.com/phpfui/mysqlslowqueryparser
- Owner: phpfui
- License: mit
- Created: 2020-12-04T17:13:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T20:02:37.000Z (about 1 year ago)
- Last Synced: 2024-03-24T01:20:21.009Z (about 1 year ago)
- Language: PHP
- Size: 50.8 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# PHPFUI\MySQLSlowLog\Parser [](https://github.com/phpfui/MySQLSlowQueryParser/actions?query=workflow%3Atests) [](https://packagist.org/packages/phpfui/mysql-slow-log-parser) 
PHP Parser for MySQL and MariaDB Slow Query Logs featuring sortable results
## Requirements
* Modern PHP version
* MySQL 5.7 or higher, or MariaDB## Usage
~~~php
$parser = new \PHPFUI\MySQLSlowQuery\Parser($logFilePath);// Return the sessions in the file as array
$sessions = $parser->getSessions();// Return all entries in file as array, or pass session number (0 based)
$entries = $parser->getEntries();if (count($entries))
{
// Get the worst offender
$entry = $parser->sortEntries()->getEntries()[0];
echo 'Query ' . implode(' ', $entry->Query) . " took {$entry->Query_time} seconds at {$entry->Time}\n";// Get the most rows examined
$entry = $parser->sortEntries('Rows_examined', 'desc')->getEntries()[0];
echo 'Query ' . implode(' ', $entry->Query) . " looked at {$entry->Rows_examined} rows\n";
}
~~~## Entries
**\PHPFUI\MySQLSlowQuery\Entry** provides details on each query.
Supported fields:
* Time
* User
* Host
* Id
* Query_time
* Lock_time
* Rows_sent
* Rows_examined
* Query (array)
* Session (zero based)**MariaDB** adds the following fields:
* Thread_id
* Schema
* QC_hit
* Rows_affected
* Bytes_sent
* Tmp_tables
* Tmp_disk_tables
* Tmp_table_sizes
* Full_scan
* Full_join
* Tmp_table
* Tmp_table_on_disk
* Filesort
* Filesort_on_disk
* Merge_passes
* Priority_queue
* explain## Sessions
**\PHPFUI\MySQLSlowQuery\Session** contains MySQL server information and are created on server restarts and log flushes. Pass the zero based session number to getEntries for only that Session's entries.
Supported fields:
* Server
* Version
* Port
* Transport## Sort Entries
By default, entries are returned in log order, but call sortEntries on the Parser to sort by any valid field (parameter 1). Sort defaults to 'desc', anything else will sort ascending.## Full Class Documentation
[PHPFUI/InstaDoc](http://phpfui.com/?n=PHPFUI%5CMySQLSlowQuery)## License
Distributed under the MIT License.