Join 4,000+ others and never miss out on new tips, tutorials, and more.
pecl install openswoole-22.0.0 | composer require openswoole/core:22.1.2
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
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.