Also check for fwrite returning 0, see http://www.php.net/manual/en/function.fwrite.php#96951
Merge pull request #10 from Traackr/master

fwrite() infinite loop