Fix potential broken resources.

In prior versions of PHP5.3.10, the stream_get_line function sometimes
breaks resources on certain platforms. I didn't find the bug fix in the
changelog but here is a clean workaround to avoid this issue. Also, the
same situation can happen in a very different (unknown) context, so this
protection is necessary.