PHP or Linux Shell: Fastest way to Read the last 10 lines of a text file and Write onto that same file
===

I need to know the fastest way possible, in PHP or Linux Command Shell, to read the last lines of a text file and also write onto that same file. I want to use 10 lines for this example.

Thanks :)