This example seems to be a great demo of why people do not like working with PHP. PHP makes the shit method the massively simpler way and the good method much harder. Now you open yourself up to risks like what happens if we accidentally let some user input change the file opened as well as the content written.
While with rails, to do basically anything, you already have a full db ready and incrementing a counter using the ORM is even easier than opening a text file. So people avoid PHP because it most likely involves dealing with absolute crap code written with no understanding.