Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 25.x
Latest version:
pecl install openswoole-25.2.0
<?php public function __construct($clientType)
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 enable-openssl or 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.
SWOOLE_SOCK_TCPSWOOLE_SOCK_TCP6SWOOLE_SOCK_UDPSWOOLE_SOCK_UDP6SWOOLE_SOCK_UNIX_DGRAMSWOOLE_SOCK_UNIX_STREAMSWOOLE_SSLSWOOLE_KEEPTo 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 SWOOLE_KEEP.