从 4.1.0 版本开始支持了对 PHP 原生 Redis 、 PDO 、 MySQLi 协程化的支持。
可使用 Swoole\Runtime::enableCorotuine() 将普通的同步阻塞 Redis 、 PDO 、 MySQLi 操作变为协程调度的异步非阻塞 IO
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();
});
新版本增加了两个方法用于跟踪协程运行。
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);
} });
BackTrace[1]:-----------------------------------------------
#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代码引发内存问题