Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5


<?php OpenSwoole\Coroutine\Socket::__construct(int $domain, int $type, int $protocol): OpenSwoole\Coroutine\Socket



Select which protocol family that the socket will use for communication. Common domain protocols are AF_UNIX or AF_LOCAL for UnixSocket, AF_INET for IPv4 and AF_INET6 for IPv6. See the description for more details on domain communication types.


Specify the socket type, this is how you set the communication type to be used. Common types are SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET and SOCK_RAW. See the description for more details on socket types.


Specify which protocol to use with the socket. Normally there only exists one protocol per socket type, so 0 is suitable to use, this means use the same socket type for the protocol. However, other protocols can be used. Some common ones are IPPROTO_TCP, IPPROTO_UDP, IPPROTO_STCP and IPPROTO_TIPC.


Returns a new coroutine socket object OpenSwoole\Coroutine\Socket. If there was an error you can use the OpenSwoole\Coroutine\Socket\Exception to catch them.


Create a new OpenSwoole\Coroutine\Socket object based on the domain family, type of socket to create and the protocol that is to be used. You handle connection operations once you have created the object.

For errors, you can either use the error class property $socket->errCode or use the OpenSwoole\Coroutine\Socket\Exception to try-catch them.

You have to install OpenSwoole core library with composer require openswoole/core to use this feature.

Last updated on February 9, 2023