Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file pointer position if file was truncated #2397

Merged
merged 1 commit into from Oct 16, 2022

Conversation

rdwebdesign
Copy link
Member

@rdwebdesign rdwebdesign commented Oct 12, 2022

What is the problem?

To ensure that the page always displays the most recent lines, the page first finds the end of the log and then starts reading new information from there.
Then while the page is kept open PHP will continue reading the new lines and will update the pointer.

The problem happens when logrotate truncates the file.
The pointer isn't updated and continues at the previous position, but there is no text to read at this position, so nothing is displayed.

The code continues to run without displaying anything until the file exceeds the previous file size (before rotation).

How does this PR solves the problem?

Simple solution:
We need to check if the pointer is beyond the end of the file.
If it is, it means the file has been truncated and we need to read it from the beginning.

What documentation changes (if any) are needed to support this PR?

none


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

  • I have read the above and my PR is ready for review. Check this box to confirm

@rdwebdesign rdwebdesign linked an issue Oct 12, 2022 that may be closed by this pull request
@rdwebdesign rdwebdesign requested a review from a team October 12, 2022 06:31
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
@yubiuser
Copy link
Member

Give me two nights to test this.

@rdwebdesign
Copy link
Member Author

Give me two nights to test this.

If you just want to wait for the log rotation, you can change the cron job to rotate the log every 5 minutes and test it any time.

@rdwebdesign rdwebdesign merged commit 31b94d1 into devel Oct 16, 2022
@rdwebdesign rdwebdesign deleted the fix/taillog_after_rotate branch October 16, 2022 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tracking] taillog.php can't auto refresh during log rotation
2 participants