Apache Log Parser Reader
These classes are designed to take an access log from Apache and convert it into a PHP object that can then be used to populate a database or parsed further.
Download the source from Github
git clone git://github.com/trianglman/ApacheLogParser.git
There are only two files necessary for the parsing: apacheLogFile.php and apacheLogRecord.php. Copy those into your source code or your PHP include path and include both files.
The primary class you’ll need to work with is \ApacheLogParser\ApacheLogFile. To prepare the parser call it’s constructor with the contents of the log file as the first argument and the CustomLog format it was created with.
$logFile = new \ApacheLogParser\ApacheLogFile($fileContents,
'%h %l %u %t \\"%r\\" %>s %b');
You can then retrieve an array of all the log entries or an individual record with the getRow() function.
//gets the full set of records $records = $logFile->getRow(); //gets just the first record $firstAccess = $logFile->getRow(0);
John Judy is a software developer who has been working with PHP since 2001. He has worked for a number of e-commerce websites and currently works for a court transcription and legal document service and retrieval firm.