Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
pecl install openswoole-22.0.0
<?php Swoole\Coroutine\Socket::__construct(int $domain, int $type, int $protocol): Swoole\Coroutine\Socket
Select which protocol family that the socket will use for communication. Common domain protocols are
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_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
Returns a new coroutine socket object
Swoole\Coroutine\Socket. If there was an error you can use the
Swoole\Coroutine\Socket\Exception to catch them.
Create a new
Swoole\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
Swoole\Coroutine\Socket\Exception to try-catch them.