<?php
ini_set('memory_limit', '-1');
$file = 'access.log';
$data = file($file);
$line = $data[count($data) - 1];
echo $line;
?>
<?php
$fp = fopen($file, "r");
$line = 10;
$pos = -2;
$t = " ";
$data = "";
while ($line > 0)
{
while ($t != "\n")
{
fseek($fp, $pos, SEEK_END);
$t = fgetc($fp);
$pos--;
}// http://www.manongjc.com
$t = " ";
$data .= fgets($fp);
$line--;
}
fclose($fp);
echo $data
?>
<?php
$fp = fopen($file, "r");
$num = 10;
$chunk = 4096;
$fs = sprintf("%u", filesize($file));
$max = (intval($fs) == PHP_INT_MAX) ? PHP_INT_MAX : filesize($file);
for ($len = 0; $len < $max; $len += $chunk)
{
$seekSize = ($max - $len > $chunk) ? $chunk : $max - $len;
fseek($fp, ($len + $seekSize) * -1, SEEK_END);
$readData = fread($fp, $seekSize) . $readData;
if (substr_count($readData, "\n") >= $num + 1)
{
// 作者:码农教程 http://www.manongjc.com
preg_match("!(.*?\n){" . ($num) . "}$!", $readData, $match);
$data = $match[0];
break;
}
}
fclose($fp);
echo $data;
?>
<?php
function tail($fp, $n, $base = 5)
{
assert($n > 0);
$pos = $n + 1;
$lines = array();
while (count($lines) <= $n)
{
try
{
fseek($fp, -$pos, SEEK_END);
}
catch (Exception $e)
{
fseek(0);
break;
}
$pos *= $base;
while (!feof($fp))
{
array_unshift($lines, fgets($fp));
}
}
return array_slice($lines, 0, $n);
}
var_dump(tail(fopen("access.log", "r+"), 10));
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有