Fix file pointer position if file was truncated #2397
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
git rebase
)