If you haven't already found the problem, I suspect it stems from the fact that fgets stops at a newline and that fread doesn't.
Once I get access to ideone tonight I can put together a test case (I don't know enough about php to make one on the fly)
If you attempt it yourself, you'll need to use numbers less than 10 to make it overflow into the next line.
The first read will contain "1\n1" and that won't equal 42. Then it Will read "2\n4" and that won't equal 42. Then it will read "2" and hit EOF and return false.
Something along those lines I suspect.