PHP读取大文本文件日志 [英] php read large text file log

查看:218
本文介绍了PHP读取大文本文件日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约600 MB的文本日志文件.

I have a text log file, about 600 MB.

我想使用php读取它并在html页面上显示数据,但是我只需要在每次运行脚本时添加的最后18行.

I want to read it using php and display the data on a html page, but I only need the last 18 lines that were added each time I run the script.

由于文件很大,因此我无法按期望读取所有内容,然后翻转数组.他们是另一种方式吗?

Since its a large file, I can't read it all in then flip the array as I would have hoped. Is their another way?

推荐答案

使用fopenfilesizefseek打开文件并仅在文件末尾开始读取它.

Use fopen, filesize and fseek to open the file and start reading it only near the end of the file.

fseek 手册页上的注释中包含完整的代码,以读取大文件的最后X行.

Comments on the fseek manual page include full code to read the last X lines of a large file.

这篇关于PHP读取大文本文件日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆