Batch 6a: application controllers base
This commit is contained in:
54
application/controllers/tools/Viewlog.php
Normal file
54
application/controllers/tools/Viewlog.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
class Viewlog extends MY_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
function show($logfile) {
|
||||
$fp = file_get_contents("/xtmp/{$logfile}.log");
|
||||
$arr = explode("\n", $fp);
|
||||
$arr = array_slice($arr, -1000);
|
||||
$arr = array_reverse($arr);
|
||||
$msg = implode("\n", $arr);
|
||||
echo "<pre>$msg</pre>";
|
||||
}
|
||||
function read_log($logfile)
|
||||
{
|
||||
$fp = fopen("/xtmp/{$logfile}.log", 'r');
|
||||
$pos = -1; // Skip final new line character (Set to -1 if not present)
|
||||
|
||||
$lines = array();
|
||||
$currentLine = '';
|
||||
$idx = 0;
|
||||
$msg = "<pre>";
|
||||
while (-1 !== fseek($fp, $pos, SEEK_END)) {
|
||||
$char = fgetc($fp);
|
||||
if (PHP_EOL == $char) {
|
||||
$msg .= $currentLine;
|
||||
echo $msg;
|
||||
$currentLine = '';
|
||||
} else {
|
||||
$currentLine = $char . $currentLine;
|
||||
}
|
||||
$pos--;
|
||||
$idx++;
|
||||
if ($idx > 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$msg .= "</pre>";
|
||||
return $msg;
|
||||
}
|
||||
function index()
|
||||
{
|
||||
|
||||
$fp = file_get_contents("/xtmp/log-order-regonline.log");
|
||||
$arr = explode("\n", $fp);
|
||||
$arr = array_slice($arr, -500);
|
||||
$arr = array_reverse($arr);
|
||||
$msg = implode("\n", $arr);
|
||||
echo "<pre>$msg</pre>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user