Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9322465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:05:51+00:00 2026-06-19T04:05:51+00:00

So I am doing a small experiment for myself, a script to read the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:05:52+00:00Added an answer on June 19, 2026 at 4:05 am

    In case anybody encounters this problem in the future I came up with a quite simple solution:

    //get to the last position of the file and get the pointer position.
    $content->seek($content->getSize());
    $lines_total = $content->key();
    $byte = $content->ftell();
    
    //all the line in the php error log starts like: [21-Feb-2013 22:34:53 UTC] so...
    $pattern = '/^\[.*\]/';
    
    for(...){
    //get the current output to preg_match it
        $data = $content->current();
    
    //go backward each time it doesnt match a line's start
        while ( preg_match( $pattern, $data ) === 0 ){
        $byte--;
        $content->fseek($byte);
        $data = $content->current();
        }
    
    //go backward 1 more position to start the next loop
        $byte--;
        $content->fseek($byte);
    }
    

    Hope this helps someone someday xD

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to teach myself PHP by doing a small image-processing type project
Im doing a small exercise to read a file which contains one long string
I was doing a small experiment with Python in my new win8 install and
I'm doing a small database driven app. I have my SQLite db file under
I am doing a small reporting project that needs to read a lot of
Im doing a small system from Haskell and im getting two errors called Last
I'm doing a small forum on the web by PHP. I was wondering how
I am doing small Silverlight app which will allow users to Create orders. I
While doing some small regex task I came upon this problem. I have a
I'm doing a small app in Excel, and I have the following code when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.