目前的Swoole 内置了丰富的协程组件供开发者直接调用以便快速实现异步非阻塞的并发编程,省去了开发者自己实现相应底层代码的麻烦:
TCP/UDP Client:Swoole\Coroutine\Client
TCP/UDP Server:Swoole\Coroutine\Server
HTTP/WebSocket Client:Swoole\Coroutine\HTTP\Client
HTTP/WebSocket Server:Swoole\Coroutine\HTTP\Server
HTTP2 Client:Swoole\Coroutine\HTTP2\Client
Redis Client:Swoole\Coroutine\Redis
Mysql Client:Swoole\Coroutine\MySQL
PostgreSQL Client:Swoole\Coroutine\PostgreSQL
在协程 Server 中使用对应的协程版 Client 来实现全异步 Server,同时 Swoole 提供了协程工具集:Swoole\Coroutine,提供了获取当前协程ID、反射调用等能力。
通过 setDefer 机制实现并发编程
我们以 Redis 和 MySQL 客