php从日志文件中查找想要的数据


        $rootPath = \think\facade\App::getRootPath();
        $directory = $rootPath.'/runtime/log/202306/'; // runtime目录路径
        $fileList = glob($directory . '/*-26.log');
        $unionid = [];
        $i = 0;
        foreach ($fileList as $filename) {
            echo "文件名:" . $filename . "\n";
            $file = fopen($filename, 'r');
            while (!feof($file)) {
                    $line = fgets($file);
                    if (!$line) continue;
                if (strpos($line, 'wechatLogin') !== false && strpos($line, 'CreatTime')) {
                    $start = strpos($line, 'wechatLogin');
                    $json = substr($line,$start+12);
                    $data = json_decode($json,true);
                    $unionid[$i]['unionid'] = $data['Unionid'];
                    $unionid[$i]['CreatTime'] = $data['CreatTime'];
                    echo $data['Unionid']."\n";
                    $i++;
                }
            }
            fclose($file);
        }
        $unionids = array_unique($unionid);
        var_dump($unionids);die;
        $member = [];
        $nor = 1;
        $count = 1;
        foreach ($unionid as $uni){
                var_dump($uni);
            $MemberPoolInfo = $MemberPoolServices->getInfo(['Unionid' => $uni['unionid']]);
                if (!$MemberPoolInfo){
                echo $uni['unionid']."-".$uni['CreatTime']."\n"; continue;
            }
        }

你可能感兴趣的:(php)