. */ if (!extension_loaded('pthreads')) { class Socket { public function __construct(int $domain, int $type, int $protocol) { $this->sock = socket_create($domain, $type, $protocol); } public function setBlocking(bool $blocking) { if ($blocking) { return socket_set_block($this->sock); } return socket_set_nonblock($this->sock); } public function setOption(int $level, int $name, $value) { if (in_array($name, [\SO_RCVTIMEO, \SO_SNDTIMEO])) { $value = ['sec' => (int) $value, 'usec' => (int) (($value - (int) $value) * 1000000)]; } return socket_set_option($this->sock, $level, $name, $value); } public function getOption(int $level, int $name) { return socket_get_option($this->sock, $level, $name); } public function __call($name, $args) { $name = 'socket_'.$name; array_unshift($args, $this->sock); return $name(...$args); } } }