Javascript:只读取大型服务器文本文件的最后x行数 [英] Javascript: Reading only the last x amount of lines of large server text file

查看:95
本文介绍了Javascript:只读取大型服务器文本文件的最后x行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我正在使用非常大的日志文件,我希望通过我的RPi上的lighttpd显示它们,但它们每天都会变大,因此很快就需要很长时间才能加载。

today I was working with very large log files and I want to display them via lighttpd on my RPi, but they grow bigger every day and thus soon will take a very long time to load.

为了防止这个问题,我想我可以有一个按钮来读取,比如说这个日志文件的最后500行。当然我对javascript的经验不多,但我认为它是可行的,对吧?

To prevent this problem I figured I would be able to have a button to read, say the last 500 lines from this log file. Of course I have not much experience with javascript, but I think it is doable, right?

无论如何,我找不到任何好的教程来描述如何在javascript,虽然我在PHP中找到了这个 ,但由于我不使用PHP,我无法使用它。因此,一个如何读取javascript中的最后500行的示例,或者每次单击从文件末尾开始的按钮逐步读取500行的按钮对我来说都是非常少的。

Anyway, I couldn't find any good tutorial describing how to do this in javascript, although I found this in PHP, but since I'm not working in PHP I cannot use it. So, a example of how to read the last 500 lines in javascript or maybe a button to progressively read 500 lines every time you click on a button starting from the end of the file would be extremely handful for me.

提前谢谢你们。

PS :我读过它是不可能阅读的使用javascript文件,但是使用AJAX调用是可能的。)

(P.S: I've read it's not possible to read a file with javascript, but with AJAX calls it is possible.)

推荐答案

不,使用JavaScript是不可能的。客户端在统一资源定位器上请求资源 - 如果这是所需的响应,则由服务器来提供最后500行。

No, it's not possible with JavaScript. The client makes a request for a resource at a uniform resource locator - it's up to your server to serve up the last 500 lines if that's the desired response.

简单的unix命令如果没有PHP, tail -500 mylog 可以被许多服务器端脚本语言解释。

Simple unix command tail -500 mylog can be interpreted by a number of server-side scripting languages if PHP isn't available to you.

这篇关于Javascript:只读取大型服务器文本文件的最后x行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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