diff --git a/src/Socket.php b/src/Socket.php index 9cadce14..738c8c74 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -24,6 +24,11 @@ if (!extension_loaded('pthreads')) { $this->sock = socket_create($domain, $type, $protocol); } + public function __destruct() + { + socket_close($this->sock); + } + public function setOption(int $level, int $name, $value) { if (in_array($name, [\SO_RCVTIMEO, \SO_SNDTIMEO])) { @@ -129,6 +134,9 @@ if (!extension_loaded('pthreads')) { { $this->protocol = getprotobynumber($protocol); } + public function __destruct() { + if ($this->sock !== NULL) fclose($this->sock); + } public function setOption(int $level, int $name, $value) {