首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
swoole 4.5.5 启用协程出错.
### 问题描述 ini 配置关闭 `swoole.enable_library` 启用协程出错. ```bash $ php -r " Swoole\Runtime::enableCoroutine(true);" Fatal error: Swoole\Runtime::enableCoroutine(): function 'swoole_exec' is not callable in Command line code on line 1 ``` ### Swoole版本,PHP版本,以及操作系统版本信息 ``` $ php -c /root/php/etc/php.ini --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.5 Built => Oct 20 2020 14:31:26 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.1.1d 10 Sep 2019 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) ``` ### 未来 library 设计疑问 我看 4.5.5 源码有 `ext-src`目录,`swoole/library`是又被加进去了吗? 为什么要把 `swoole/library` 的设计加进去, 而不单独用 composer 维护 `swoole/library` ?
发布于5年前 · 9 次浏览 · 来自
提问
Moln
### 问题描述 ini 配置关闭 `swoole.enable_library` 启用协程出错. ```bash $ php -r " Swoole\Runtime::enableCoroutine(true);" Fatal error: Swoole\Runtime::enableCoroutine(): function 'swoole_exec' is not callable in Command line code on line 1 ``` ### Swoole版本,PHP版本,以及操作系统版本信息 ``` $ php -c /root/php/etc/php.ini --ri swoole swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.5.5 Built => Oct 20 2020 14:31:26 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.1.1d 10 Sep 2019 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => Off => Off swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608 ``` ### 相关代码 ```php 请将代码粘贴至此处(请勿用截图) ``` ### 未来 library 设计疑问 我看 4.5.5 源码有 `ext-src`目录,`swoole/library`是又被加进去了吗? 为什么要把 `swoole/library` 的设计加进去, 而不单独用 composer 维护 `swoole/library` ?
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-10-21
鲁飞
1. 你在phpini中关掉了内置library,就需要手动使用composer加载library,swoole_exec 是在library当中的。 2. ext-src目录是将swoole相关的放进来了(让根目录,扩展目录更清晰),swoole/library是会生成头文件,也在其中。
赞
0
回复
2020-10-22
Moln
回复
鲁飞
> 你不要用library相关的操作就可以?协程化curl是在library中的。 > 启用协程出错. 创建协程不是go或者co\run? 我会用到 `curl` 扩展, 但不会用到 `library` 里的 `Swoole\Curl`. 我的项目不想用到,也用不到 library 里的任何东西,所以需要关闭 `swoole.enable_library = Off`. 比如,下面代码 在 swoole `4.3.1` 中,就能脱离 `library` , 能正常运行. ```php <?php Swoole\Runtime::enableCoroutine(true); for ($i = 0; $i < 3; $i++) go(function () { sleep(1); echo date("Y-m-d H:i:s"), "\n"; }); ``` **swoole `4.3.1` 运行结果:** ``` 2020-10-22 09:21:20 2020-10-22 09:21:20 2020-10-22 09:21:20 ``` **swoole `4.5.5` 运行结果:** ``` PHP Fatal error: Swoole\Runtime::enableCoroutine(): function 'swoole_exec' is not callable in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 PHP 2. Swoole\Runtime::enableCoroutine() Command line code:1 ``` > 你在phpini中关掉了内置library,就需要手动使用composer加载library,swoole_exec 是在library当中的。 我的意思就是能否像 `v4.3.1`,开发者使用时,能完全脱离 `library` ? 目前给的使用感受,`swoole` 已经完全捆绑了 `library`. > ext-src目录是将swoole相关的放进来了(让根目录,扩展目录更清晰),swoole/library是会生成头文件,也在其中。 目录整理没意见,这很好.. 另外 `v4.5.3` 也是这种情况.
赞
0
回复
2020-10-22
鲁飞
回复
Moln
```php Swoole\Runtime::enableCoroutine(true, SWOOLE_HOOK_SLEEP); for ($i = 0; $i < 3; $i++) go(function () { sleep(1); echo date("Y-m-d H:i:s"), "\n"; }); ```
赞
0
回复
2020-10-21
Moln
> 你在phpini中关掉了内置library,就需要手动使用composer加载library,swoole_exec 是在library当中的。 这样看来 `swoole.so` 扩展是必须依赖,`swoole/library` ? 不能像以前版本一样 关闭内置 library,也不引用 `swoole/library`.
赞
0
回复
2020-10-22
鲁飞
回复
Moln
你不用library相关的操作就可以了?协程化curl是在library中的。 启用协程出错. 创建协程不是go或者co\run吗?
赞
0
回复
2020-10-22
鲁飞
还是没明白你想干什么,创建协程不需要开启一键协程化。 你不用`Swoole\Runtime::enableCoroutine(true);`或者设置对应需要协程化的flags即可
赞
0
回复