首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
开启协程后,stream_set_blocking 被强制设定阻塞状态了?
### 问题描述 在 swoole协程应用中, 使用 [`symfony/process`](https://packagist.org/packages/symfony/process) 库遇到问题,`stream_set_blocking($resource, 0)` 设置非阻塞无效,导致应用库不能按预期执行. ### Swoole版本,PHP版本,以及操作系统版本信息 ``` ~$ php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.2 Built => Jul 17 2020 14:01:02 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.1.1g 21 Apr 2020 pcre => enabled mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ~$ uname -a && php -v && gcc -v Linux xiemaomao 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux PHP 7.4.9 (cli) (built: Aug 7 2020 14:29:36) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies with Sdebug v2.9.3-dev, Copyright (c) 2002-2020, by Derick Rethans Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) ``` ### 相关代码 ```php \Swoole\Runtime::enableCoroutine(true); go(function () { @proc_open('echo hello && sleep 3000 && echo world', [ ['pipe', 'r',],['pipe', 'w',], ['pipe', 'w',], ],$pipes); foreach ($pipes as $pipe) { stream_set_blocking($pipe, 0); //开启协程后,非阻塞设定都无效了. } var_dump(fread($pipes[1], 1024)); //当前会阻塞读取 var_dump(fread($pipes[1], 1024)); }); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 不要影响 `stream_set_blocking` 非阻塞设置. ```php \Swoole\Runtime::enableCoroutine(true); go(function () { @proc_open('echo hello && sleep 3000 && echo world', [ ['pipe', 'r',],['pipe', 'w',], ['pipe', 'w',], ],$pipes); foreach ($pipes as $pipe) { stream_set_blocking($pipe, 0); // 实现非阻塞 } var_dump(fread($pipes[1], 1024)); // 实现非阻塞读取 var_dump(fread($pipes[1], 1024)); }); ```
发布于4年前 · 2 次浏览 · 来自
提问
Moln
### 问题描述 在 swoole协程应用中, 使用 [`symfony/process`](https://packagist.org/packages/symfony/process) 库遇到问题,`stream_set_blocking($resource, 0)` 设置非阻塞无效,导致应用库不能按预期执行. ### Swoole版本,PHP版本,以及操作系统版本信息 ``` ~$ php --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.2 Built => Jul 17 2020 14:01:02 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.1.1g 21 Apr 2020 pcre => enabled mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ~$ uname -a && php -v && gcc -v Linux xiemaomao 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux PHP 7.4.9 (cli) (built: Aug 7 2020 14:29:36) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies with Sdebug v2.9.3-dev, Copyright (c) 2002-2020, by Derick Rethans Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) ``` ### 相关代码 ```php \Swoole\Runtime::enableCoroutine(true); go(function () { @proc_open('echo hello && sleep 3000 && echo world', [ ['pipe', 'r',],['pipe', 'w',], ['pipe', 'w',], ],$pipes); foreach ($pipes as $pipe) { stream_set_blocking($pipe, 0); //开启协程后,非阻塞设定都无效了. } var_dump(fread($pipes[1], 1024)); //当前会阻塞读取 var_dump(fread($pipes[1], 1024)); }); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 不要影响 `stream_set_blocking` 非阻塞设置. ```php \Swoole\Runtime::enableCoroutine(true); go(function () { @proc_open('echo hello && sleep 3000 && echo world', [ ['pipe', 'r',],['pipe', 'w',], ['pipe', 'w',], ],$pipes); foreach ($pipes as $pipe) { stream_set_blocking($pipe, 0); // 实现非阻塞 } var_dump(fread($pipes[1], 1024)); // 实现非阻塞读取 var_dump(fread($pipes[1], 1024)); }); ```
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2020-08-27
宇润
v4.5.3RC1中已经修复这个问题,可以尝试一下
赞
0
回复
微信公众号
热门内容
作者其它话题
- swoole 4.5.5 启用协程出错.
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。