Swoole-src: Question: async Swoole client

Created on 10 Jun 2020  ·  8Comments  ·  Source: swoole/swoole-src

I have used SwooleClientAsync for async SSL TCP connections. Recently I've noticed that it is deprecated. So I have the following questions:

  • How long will it be supported?
  • Is there any reason to replace it by a coroutine client?
  • What coroutine client is better to replace SwooleClientAsync SSL (CoSocket or SwooleCoroutineClient)?
  • Does SwooleCoroutineClient support SSL?
  • Is there any example which demonstrates the best way to migrate?

Thank you!

good question

Most helpful comment

@idealogica although async clients will be maintained and fixing the bugs, but we would recommend move to the coroutine client which is much more simple.

These SSL settings are still supported as is. We will update the docs soon.

All 8 comments

Q: How long will it be supported?

A: We just don’t develop new features, but if there are bugs, we will fix them, there is no end time

Does SwooleCoroutineClient support SSL?

Yes, Here is the example

Co\run(function(){
  $client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP | SWOOLE_SSL);
  if (!$client->connect('127.0.0.1', 9501, 0.5))
  {
      echo "connect failed. Error: {$client->errCode}\n";
  }
  $client->send("hello world\n");
  echo $client->recv();
  $client->close();
});

Is there any reason to replace it by a coroutine client?

Async client will cause callback hell, Coroutine client is easier to use

Q: How long will it be supported?

A: We just don’t develop new features, but if there are bugs, we will fix them, there is no end time

Then why the documentation has been removed from the docs section? https://www.swoole.co.uk/docs/module. For example https://www.swoole.co.uk/docs/modules/swoole-client/methods async client methods list gives 404 error. We still use this client, so it would be good to keep the SwooleClientAsync documentation.

Also recent versions of ide-helper package don't include SwooleClientAsync helpers. So it looks like SwooleClientAsync is gone :(

Does SwooleCoroutineClient support SSL?

Yes, Here is the example

Co\run(function(){
  $client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP | SWOOLE_SSL);
  if (!$client->connect('127.0.0.1', 9501, 0.5))
  {
      echo "connect failed. Error: {$client->errCode}\n";
  }
  $client->send("hello world\n");
  echo $client->recv();
  $client->close();
});

Are there any options to control SSL behaviour? No such options mentioned in the docs. I'm using the following with SwooleClientAsync:

                'ssl_verify_peer' => false,
                'ssl_allow_self_signed' => true,
                'ssl_verify_peer_name' => false,
                'ssl_host_name' => $this->requestUri->getHost(),
                'verify_peer' => false,
                'allow_self_signed' => true,
                'verify_peer_name' => false,
                'timeout' => 20,
                'debug_mode'=> DEBUG,
                'keep_alive' => false,
                'socket_buffer_size' => 16 * 1024 * 1024,

Are they supported?

@idealogica although async clients will be maintained and fixing the bugs, but we would recommend move to the coroutine client which is much more simple.

These SSL settings are still supported as is. We will update the docs soon.

Thank you so much for the responses and for updating the docs! :)

I have migrated successfully btw ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chenye2017 picture chenye2017  ·  3Comments

pthreat picture pthreat  ·  3Comments

zuozhehao picture zuozhehao  ·  3Comments

rovico picture rovico  ·  4Comments

Gemorroj picture Gemorroj  ·  3Comments