Package Documentation

  • Readme

    PHPFUI\MySQLSlowLog\Parser Tests Latest Packagist release

    PHP Parser for MySQL Slow Query Logs featuring sortable results

    Requirements

    • PHP 7.1 or higher
    • MySQL 5.7 or higher

    Usage

    $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)

    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
    • 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

    Via PHPFUI/InstaDoc

    License

    Distributed under the MIT License.

Namespaces
\PHPFUI\MySQLSlowQuery\Exception
Classes
PHPFUI\MySQLSlowQuery\BaseObject
PHPFUI\MySQLSlowQuery\Entry
PHPFUI\MySQLSlowQuery\Exception
PHPFUI\MySQLSlowQuery\Parser
PHPFUI\MySQLSlowQuery\Session
© 2021 Bruce Wells
Search Namespaces \ Classes
Configuration