isConnected() instead feof() (Line 587)

feof() throws error if socket is null: 

```
Warning: feof(): null is not a valid stream resource in - on line 587
```