/**
  * @param string    $host
  * @param int       $port
  * @param int       $timeout
  * @param bool      $persistent
  *
  * @return resource
  * @throws ConnectionException
  */
 public function open($host, $port, $timeout, $persistent = true)
 {
     if (!is_null($this->socket)) {
         $this->close();
     }
     if ($persistent) {
         $socket = @pfsockopen($host, $port, $errno, $errstr, $timeout);
     } else {
         $socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
     }
     if (false === $socket) {
         throw ConnectionException::CouldNotConnect($host, $port, $errno, $errstr);
     } else {
         return $this->socket = $socket;
     }
 }