Is there a way to write the first line of a file and keep the other lines already written ?
For example:
-> Line 5
-> Line 4
-> Line 3
-> Line 2
-> Line 1
We can call it a reverse from the log_to_file function. The only difference is that the text written inside of the file will be on a reversed order.
Also, if possible, to keep only a specific number of lines, for example maximum 100.
I found a sample from PHP but I think that copying the entire file content into memory, just to add one more line then rewrite the new content is bad for memory.
I am wondering if it's possible to write something on the first line of a file without copying the entire file content.