ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 4.2.13 [TOC] ## 修复(需注意的不兼容变更) * 修复Redis订阅模式API设计问题导致重复订阅和订阅消息丢失的问题 (详见:[订阅模式文档](https://wiki.swoole.com/wiki/page/1041.html)或 附录示例代码) ([#2305](https://github.com/swoole/swoole-src/pull/2305)) (@windrunner414) * 使用协程化时, 不能再`pconnect`等传统连接复用的方法, 否则会产生多协程同时复用同一个Socket的问题 ([7b1e786](https://github.com/swoole/swoole-src/commit/7b1e78643c40b0c8ace1bca8c7b10e3064cce488)) (@shiguangqi) ## 增强 * 协程客户端支持全双工 ([#2350](https://github.com/swoole/swoole-src/pull/2350)) (@twosee) * 支持安全的跨协程close ([#2327](https://github.com/swoole/swoole-src/pull/2327)) (@twosee) * [RFC-1015](https://github.com/swoole/rfc-chinese/issues/38): 非Worker进程允许单向投递任务 ([222043a](https://github.com/swoole/swoole-src/commit/222043a235b7a4eb62b7d14f1ab38844c7bdd510)) (@matyhtf) * `swoole_strerror`支持自动转换系统错误码和Swoole底层错误码为文字, 无需指定参数 ([c92f444](https://github.com/swoole/swoole-src/commit/c92f44460b1762a3165ac3d8e2733b5a6db19092)) (@twosee) * gdb追踪工具支持查看定时器和reactor信息 ([2beb563](https://github.com/swoole/swoole-src/commit/2beb563abe3f2dec8b7a9f0327fb63f0bc946e14)) (@shiguangqi) * 使用Redis集群时出现MOVED和ASK错误时将自动转移到对应服务端 ([#2299](https://github.com/swoole/swoole-src/pull/2299)) (@windrunner414) * 底层代码优化, 减少收包时的内存拷贝 (@matyhtf) * 现在调用`Co\Socket->close()`将会立即close fd, 而非等待对象析构后close, close后调用其它任何API将返回BADF错误 (和系统API保持一致) ([7a61963](https://github.com/swoole/swoole-src/commit/7a6196359686d749b7e045908414f82b105dbbdc)) (@twosee) * 一些非法的参数不再会导致致命错误而是产生一个警告, 因为外部传参有时不可控, 存在一定风险 ([cd432d3](https://github.com/swoole/swoole-src/commit/cd432d31c3e358fcdb297390967a3187b35433f9)) (@twosee) * 使用协程化后API兼容性增强(和同步阻塞表现一致) ([36687e8](https://github.com/swoole/swoole-src/commit/36687e8081a36060f56ceca4272fb6358c092529)) (@matyhtf) * 现在swoole\\src可以同时作为C\\C++库使用(libswoole) ## 修复 * 修复初次加载前存在大量对象时可能的coredump问题 ([4ddeedb](https://github.com/swoole/swoole-src/commit/4ddeedbb06351b03dc94c495eaae60b8a007e65e)) (@twosee) * 修复没有DNS缓存时尝试清除缓存导致的coredump ([#2288](https://github.com/swoole/swoole-src/pull/2288)) (@mabu233) * 启用`task_enable_coroutine`后, 错误地调用`Server->finish`会触发致命错误 ([156ede6](https://github.com/swoole/swoole-src/commit/156ede623b7fff6ec1aa9c290bd5cae8fca1d51a)) (@twosee) * 现在php.ini配置指定`On`和`Off`时能正确显示(而不是显示0) ([fe25982](https://github.com/swoole/swoole-src/commit/fe259822fc316adbb576a116f75137cc934d6b13)) (@twosee) * 修复`Co::getaddrinfo`后几个参数接收错误的BUG ([#2273](https://github.com/swoole/swoole-src/pull/2273)) (@mabu233) * 修复dispatch\_func在UDP模式下时fd错误的问题 ([#2306](https://github.com/swoole/swoole-src/pull/2306)) (@mabu233) * 修复dispatch\_func在指定函数名时不生效的BUG, 回调在未接收包体数据参数时减少内存拷贝(如基于fd分配的模式) ([2bc49e4](https://github.com/swoole/swoole-src/commit/2bc49e4dc16d408f7cc5043c09d7435802abbdcf)) (@twosee) * Task过期时将不再触发PHP警告(而是swoole底层的日志警告) ([54eee5e](https://github.com/swoole/swoole-src/commit/54eee5e128daf85d72b1cb2d59e0d9c08827653b)) (@matyhtf) * 修复进程重启时enable\_coroutine失效问题 ([#2310](https://github.com/swoole/swoole-src/pull/2310)) * 修复进程id属性不正确的问题 ([#2313](https://github.com/swoole/swoole-src/pull/2313)) (@junwei-qu) * 修复BASE模式下错误地在onStart回调中使用异步API导致的问题 ([#2308](https://github.com/swoole/swoole-src/issues/2308)) (@matyhtf) * 修复BASE模式下manager\_id不正确 ([e18e013](https://github.com/swoole/swoole-src/commit/e18e013cac20d3d4e332360ddcc7ba5ffb035346)) (@matyhtf ) * 修复mmap使用SEEK\_END偏移错误 ([#2314](https://github.com/swoole/swoole-src/pull/2314)) (@junwei-qu) * 修复getSocket内存泄漏 ([ec8c4b2](https://github.com/swoole/swoole-src/commit/ec8c4b2be95aa27d0984bd85460c40da7a088e34)) (@twosee) * 优化stream模式 ([47e0e9e](https://github.com/swoole/swoole-src/commit/47e0e9ec7e56c7c664a1d04acb0f8fbe40710e98)) (@matyhtf ) * 修复同步客户端KEEP模式下连接复用在某些情况下导致的BUG ([4c5728b](https://github.com/swoole/swoole-src/commit/4c5728b5b552de09d9bf6bd323fb62473071a4a5)) (@matyhtf) * 修复MacOS下`Atmoic`多次`wait`和`wakeup`溢出的问题 ([fbccb25](https://github.com/swoole/swoole-src/commit/fbccb252707812f1791280bcaaa2048b7e8f601a)) (@twosee) * 修复开启static\_handler存在目录遍历攻击风险的问题, 这是一个便利性调试功能, 请勿用于生产 ([#2323](https://github.com/swoole/swoole-src/pull/2323)) (@windrunner414) * 修复未检查futex\_wait系统调用的返回值 ([#2351](https://github.com/swoole/swoole-src/pull/2351)) (@junwei-qu) * 修复Reids::ZAdd API解析参数的BUG, 并修复其它潜在的类型转换问题 ([#2321](https://github.com/swoole/swoole-src/issues/2321)) ([21e0497](https://github.com/swoole/swoole-src/commit/21e04977659ca48e69f65bda097683eaef98f36e)) ([a0e612f](https://github.com/swoole/swoole-src/commit/a0e612f4308fb8702d84a38d8d8a4921b096a733)) ([00134cf](https://github.com/swoole/swoole-src/commit/00134cfa7d730c10edc623abae4866cfec2acc23)) ([f5a331e](https://github.com/swoole/swoole-src/commit/f5a331e011f378ef36ab3f7e47af12b35e53e374)) ([5f87f17](https://github.com/swoole/swoole-src/commit/5f87f178ccc1f9dbab65745618cd22351e896574)) ([a15f094](https://github.com/swoole/swoole-src/commit/a15f094e42eba6df67e0b7678648c261f6e05c7c)) ([67f3285](https://github.com/swoole/swoole-src/commit/67f328541e5a0cb17e532038c7a35b4666e42b1b)) ([808f578](https://github.com/swoole/swoole-src/commit/808f57826160578223e5e90ba4d370930410b6a9)) ([d118fe3](https://github.com/swoole/swoole-src/commit/d118fe3f9e5b3b15877bb49eacccc38bd4b992d8)) ([5294473](https://github.com/swoole/swoole-src/commit/52944739f61e36cb49a2828ec699da3bfb5d7c63)) ([48f6790](https://github.com/swoole/swoole-src/commit/48f6790deeaa5b2e6fae90ada1ca6d87a99c410e)) ([0105c7f](https://github.com/swoole/swoole-src/commit/0105c7f6c24551434e4e7542c4b6fb1b3ca31959)) ([ba6c8b4](https://github.com/swoole/swoole-src/commit/ba6c8b4c25c27a62a3ad8dc035d19d6012ee0e64)) (@matyhtf) * 修复发送数据时没有使用函数指针可能导致的第三方hook失败 ([89ba2da](https://github.com/swoole/swoole-src/commit/89ba2dafe75b83ca8e459345c719f8e83aa53480)) (@matyhtf ) * 兼容性: Mysql escape方法出错时将返回空字符串而不是FALSE * 修复Timer::tick方法有传参时产生的内存泄露 ([7e15141](https://github.com/swoole/swoole-src/commit/7e15141177b84c9a18030f1f8b7fcdcd9a29a83c)) (@mabu233) * 修复自定义进程不能自动退出 ([2901ce0](https://github.com/swoole/swoole-src/commit/2901ce0a975486e1b656906858a0b7d2f1c52603)) (@matyhtf) * 修复协程化后连接超时时间影响到读操作超时时间 ([a990540](https://github.com/swoole/swoole-src/commit/a9905408989dcee4b31a3d5b6ca68c9ecde855e6)) (@shiguangqi) * 修复`Co\Client`指定收包规则后, 传参超时时间不生效的问题 ([#2346](https://github.com/swoole/swoole-src/issues/2346)) (@twosee) * Server在BASE模式下不再受`buffer_output_size`限制, 仅受`socket_buffer_size`限制 ([#2326](https://github.com/swoole/swoole-src/issues/2326)) (@matyhtf) * 修复在FREEBSD下的编译错误 ([#2325](https://github.com/swoole/swoole-src/issues/2325)) (@matyhtf) ## 单元测试 * 更多的单元测试 * 新增内存测试到valgrind分支, 分离alpine测试到alpine分支, 自动触发测试 * 测试支持在任意装有docker的主机上运行并自动部署基于docker的swoole/mysql/redis容器, 详情参阅源码目录下travis文件夹内的README文档 ## 其它 * Swoole\\Serialize现已支持在PHP73下正常运作, 但仍标记为待废除的功能, 不建议使用 ## 附录 ### 协程Redis订阅模式示例代码: ~~~ $redis = new Swoole\Coroutine\Redis(); $redis->connect('127.0.0.1', 6379); if ($redis->subscribe(['channel1', 'channel2', 'channel3'])) // 或者使用psubscribe { while ($msg = $redis->recv()) { // msg是一个数组, 包含以下信息 // $type # 返回值的类型:显示订阅成功 // $name # 订阅的频道名字 或 来源频道名字 // $info # 目前已订阅的频道数量 或 信息内容 list($type, $name, $info) = $msg; if ($type == 'subscribe') // 或psubscribe { // 频道订阅成功消息,订阅几个频道就有几条 } else if ($type == 'unsubscribe' && $info == 0) // 或punsubscribe { break; // 收到取消订阅消息,并且剩余订阅的频道数为0,不再接收,结束循环 } else if ($type == 'message') // 若为psubscribe,此处为pmessage { // 打印来源频道名字 var_dump($name); // 打印消息 var_dump($info); // 处理消息 if ($need_unsubscribe) // 某个情况下需要退订 { $redis->unsubscribe(); // 继续recv等待退订完成 } } } } ~~~