So I am doing a small experiment for myself, a script to read the php errors’ log file (with SplFileObject) and output it formatted on the browser.
I though it would be more logic to display it in reversed order (the latest errors on top).
To use the “normal” order I would just display each line and call $file->next(); to move the pointer, but as I’m doing it the other way around, and there’s not a prev() or previous() method as far as I know, the only way I found was using seek():
for($i = $lines_total - $start_at; $i > $lines_total - $start_at - $lines_to_get; $i--){
$content->seek($i);
$data = $content->current();
if(empty($data)){
continue;
}
}
But this is incredibly slow (around 7 Secs for a 16mb file). If I do it in the normal order it’s instant.
Do anyone knows any method? or what I’m trying to do is crazy? xD I’m just a designer forced to code, so I am not very familiarized with pointers and stuff like that.
In case anybody encounters this problem in the future I came up with a quite simple solution:
Hope this helps someone someday xD