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 7988113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:20:31+00:00 2026-06-04T12:20:31+00:00

I am trying to build a small demon in PHP that analyzes the logfiles

  • 0

I am trying to build a small demon in PHP that analyzes the logfiles on a linux system. (eg. follow the syslog).

I have managed to open the file via fopen and continuosly read it with stream_get_line. My problem starts when the monitored file is deleted and recreated (eg when rotating logs). The program then does not read anything anymore, even if the file grew larger than previously.

Is there an elegant solution for this? stream_get_meta_data does not help and using tail -f on the command line shows the same problem.

EDIT, added sample code
I tried to boil down the code to a minimum to illustrate what I am looking for

<?php
$break=FALSE;
$handle = fopen('./testlog.txt', 'r');
do {
    $line = stream_get_line($handle, 100, "\n");
    if(!empty($line)) {
        // do something
        echo $line;
    }
    while (feof($handle)) {
      sleep (5);
      $line = stream_get_line($handle, 100, "\n");
      if(!empty($line)) {
        // do something
        echo $line;
      }
      // a commented on php.net indicated it is possible
      // with tcp streams to distinguish empty and lost
      // does NOT work here  --> need somefunction($handle)
      if($line !== FALSE && $line ='') $break=TRUE;
    }
} while (!$break);
fclose($handle);
?>
  • 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-04T12:20:33+00:00Added an answer on June 4, 2026 at 12:20 pm

    When log files are rotated, the original file is copied, then deleted, and a new file with the same name is created. It may have the same name as the original file, but it has a different inode. Inodes (dumbed down description follows) are like hidden incremental index numbers for your files. You can change the name of a file, or move it, but it takes the inode with it. Once that original log file is deleted, you can’t re-open a file with the same name using the same file handler, because the inode has changed. Your best bet is detect the failure, and attempt to open the new file.

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

Sidebar

Related Questions

G'day guys, trying to build a small invoicing system (that can generate PDF's using
I am currently trying to build a small system that read's in a bunch
I have a small demo contact form that I'm trying to build using Ajax.
I'm trying to build a small program that hosts vst effects and I would
I'm trying to build a small testing app with erlang+mnesia. I have a user
I'm trying to build a small class-like container that will make it a little
I'm trying to build small web-system (url shortcutting) using nonsql Cassandra DB, the problem
I'm trying to build a Javascript listener for a small page that uses AJAX
I am trying to build a small applet that provides some 3d functionality into
i am trying to build a small email worker that sends my emails. The

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.