ThinkPHP6.0如何分析IIS日志?
public function checkIndexJs() {
$file = root_path() . DIRECTORY_SEPARATOR . "runtime" . DIRECTORY_SEPARATOR . "log";
$temp = scandir($file);
// 遍历文件夹
$result = [];
$resultAll = [];
foreach ($temp as $v) {
$log = $file . DIRECTORY_SEPARATOR . $v;
if (file_exists($log) && $v !== "." && $v !== "..") {
// 读取文件内容
$info = fopen($log, "r");
// 输出文本中所有的行,直到文件结束为止。
while (!feof($info)) {
// fgets()函数从文件指针中读取一行
$itemStr = fgets($info);
// 判断是否包含index.js
if (strpos($itemStr, "index.js") !== false) {
preg_match("/(http|https)://([wd-_]+[.wd-_]+)[:d+]?([/]?[w/.]+)/i", $itemStr, $domain);
if (isset($domain[2])) {
// 放入数组,方便计算,去除重复
$a = $result[$v] ?? [];
// 记录到当前数组
if (!in_array($domain[2], $a)) {
$result[$v][] = $domain[2];
}
if (!in_array($domain[2], $resultAll)) {
$resultAll[] = $domain[2];
}
}
}
}
fclose($info);
}
}
dump($result, $resultAll);
}
实现目标及原理:循环log目录的每一个文件,读取每一行,判断是否包含index.js,然后读取来源域名并存入不重复的数组内,这样我们得到的结果就是所有访问过(调用过)index.js的域名和每天的一个调用情况。
以上是 ThinkPHP6.0如何分析IIS日志? 的全部内容, 来源链接: utcz.com/z/514370.html