function __destruct() { parent::__destruct(); if ($this->connected) { socket_shutdown($this->socket); $this->socket = null; $this->connected = false; } }