Jump to content

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


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>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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