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
The type of the client to create, see constants below.
A new TCP/UDP client instance.
Create a coroutine TCP/UDP client within a coroutine context, with or without SSL.
Compile Swoole with
with-openssl-dir to support SSL. Also add
SWOOLE_SSL to the constructor.
You can use the following client types when creating a new TCP/UDP client.
To establish an SSL connection.
<?php $client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP | SWOOLE_SSL); ...
To create persistent TCP connection:
<?php $client = new Swoole\Coroutine\Client(SWOOLE_TCP | SWOOLE_KEEP); ...
A persistent connection created by using
SWOOLE_KEEP will not be closed, even when calling
$client->close(). This makes it easier when having to reconnect again after the server disconnects or an error happens, the connection details are saved. The client deconstructor will handle any connection closing when using