deprecation warning fix & unreachable code fix

* ereg is deprecated since PHP 5.3
* socket should be closed before return (unreachable code)