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
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\Client->enableSSL(): bool
None
Returns true
when successful and false
when not.
Enable SSL encryption dynamically.
Even though you can setup SSL connections right from the start of a client using the configuration, you can also use this method to enable SSL dynamically when you need to.
You can only use this method when SSL has not been enabled through the client configuration, you must also establish a connection to a server first. When calling this method, it will block until the SSL handshake has finished.
<?php
$client = new Swoole\Client(SWOOLE_SOCK_TCP);
if(!$client->connect('127.0.0.1', 9501, -1))
{
exit("connect failed. Error: {$client->errCode}\n");
}
$client->send("Hello World! - No SSL\n");
echo "Data from server: " . $client->recv() . "\n\n";
// Enable SSL
if($client->enableSSL())
{
// The handshake is complete, the data sent and received at this time is encrypted using SSL
$client->send("Hello World! - With SSL\n");
echo $client->recv();
}
$client->close();