Jump to content

[SOLVED] Getting Apache's log file data using PHP?


random1

Recommended Posts

Hey All,

 

I'd like to get some help on getting the content of Apache's log files (e.g. apache\logs\error.log).

 

I'd like to get the last 20 entries/lines in the file to avoid loading a giant log file.  :)

 

Any ideas? :confused: Best would be an array of each line split into type.

I was able to do it this way:

 

<?php
$file = '../../Apache/logs/error.log'; //Change to your path
$fp = fopen($file, 'r');
fseek($fp, filesize($file)-2500);
$content = array_slice(array_reverse(explode("\n",fread($fp, 2500))), 0, 21);
array_shift($content);
echo "<pre>";
print_r($content);
echo "</pre>";

Thanks AlexWD! :D :D

 

I ended up using:

 

$file = 'D:\\xampp\\apache\\logs\\error.log'; // Path of Apache log file
$fp = fopen($file, 'r');
fseek($fp, filesize($file)-5000);
$content = array_slice(array_reverse(explode("\n",fread($fp, 5000))), 0, 21);
array_shift($content);
echo '<pre>';
print_r($content);
echo '</pre>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.