Logo  

CS479/579 - Web Programming II

Displaying ./code/PHP/errors.php

<!DOCTYPE html>
<html>
<head>
 <title> Apache Error log </title>
 <meta charset='utf-8'>
</head>
<body>
<h1> CS server error log </h1>
<pre>
<?php
  $file = "/var/log/httpd/error_log";
  /**
   * If the file is less than 1MB, then read the whole thing, otherwise just
   * read 1MB from the end of the file:
   */
  if (filesize($file) < 1048576) $data = file_get_contents($file);
  else $data = file_get_contents($file, false, NULL, -1048576);

  // Split the file data into an array of lines:
  $lines = explode("\n", $data);
  // Print out the lines from the end of the array of lines:
  for($i=count($lines)-1, $j=0; $i >= 0 && $j < 100 ; $i--, $j++) {
    echo "{$lines[$i]}\n";
  }
?>
</pre>
</body>
</html>