PHP code example of jkh / apache-log-parser-library

1. Go to this page and download the library: Download jkh/apache-log-parser-library library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jkh / apache-log-parser-library example snippets


$parser = new \jkh\ApacheLogParser\ApacheLogParser();

$log_file = '/var/log/apache2/access.log';

$handle = fopen($log_file, "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        $entry = $parser->parse($line);
    }
    fclose($handle);
} else {
    echo "An error occurred: unable to open the file!\n";
}