从4.1.0
版本开始支持了对PHP
原生Redis
、PDO
、MySQLi
协程化的支持。php
可以使用Swoole\Runtime::enableCorotuine()
将普通的同步阻塞Redis
、PDO
、MySQLi
操做变为协程调度的异步非阻塞IO
git
Swoole\Runtime::enableCoroutine(); go(function () { $redis = new redis; $retval = $redis->connect("127.0.0.1", 6379); var_dump($retval, $redis->getLastError()); var_dump($redis->get("key")); var_dump($redis->set("key", "value")); $redis->close(); });
新版本增长了两个方法用于跟踪协程运行。github
Coroutine::listCoroutines()
可遍历当前全部协程Coroutine::getBackTrace($cid)
可获取某个协程的函数调用栈function test1() { test2(); } function test2() { while(true) { co::sleep(10); echo __FUNCTION__." \n"; } } $cid = go(function () { test1(); }); go(function () use ($cid) { while(true) { echo "BackTrace[$cid]:\n-----------------------------------------------\n"; //返回数组,须要自行格式化输出 var_dump(co::getBackTrace($cid))."\n"; co::sleep(3); } });
----------------------------------------------- #0 Swoole\Coroutine::sleep(10) called at [/home/htf/workspace/swoole/examples/coroutine/backtrace.php:8] #1 test2() called at [/home/htf/workspace/swoole/examples/coroutine/backtrace.php:3] #2 test1() called at [/home/htf/workspace/swoole/examples/coroutine/backtrace.php:14]
Co\Channel
C底层代码为C++, 解决复杂场景的非预期结果, 实现高稳定Co\Http\Client
C底层代码为C++协程模式, 解决异步时序问题, 实现高稳定exit
, 此时将会抛出可捕获的\Swoole\ExitException
异常open_websocket_close_frame
配置, 能够在onMessage事件中接收close帧Http\Response->gzip()
方法,改成使用http_compression
配置项。底层会自动判断客户端传入的Accept-Encoding
选择合适的压缩方法, 新增谷歌BR压缩支持Co\Http\Client->addData()
方法,可将内存中的数据做为上传文件内容进行发送Solaris
系统支持MAX_FRAME_SIZE
分帧发送和MAX_HEADER_LIST_SIZE
处理, 客户端增长isStreamExist
方法检测是否存在对应流swoole_http_response->status
增长reason
参数onRequest
回调中没有协程的问题tasking_num
某些特殊状况下变为-1
的问题Co\Http\Client
使用了create_obj
和free_obj
保证内存安全, 防止错误的PHP代码引起内存问题