swoole:must be forked outside the coroutine
背景介绍
最近正在学习Swoole的一些用法,然后就碰到了这个问题:PHP Fatal error: Uncaught Swoole\Error: must be forked outside the coroutine in xxx
。
提示报错的代码是:
\Swoole\Process::daemon($nochdir = true, $noclose = true);
使用的背景是在nginx
+php-fpm
,swoole的版本是4.5.3
。
尝试解决方案
根据 github.com/swoole/swoole-src/issue... 提到的一些解决方案都试过了,如:
- 使用如下方案报错:
PHP Fatal error: swoole_async_set(): eventLoop has already been created. unable to change settings in xxx .
swoole_async_set([ 'enable_coroutine' => false ]);
- 第二种方案报错:
must be forked outside the coroutine
\Swoole\Coroutine::set(['enable_coroutine' => false]);
- 第三种方案报错:
Uncaught Swoole\Error: must be forked outside the coroutine
ini_set('swoole.enable_coroutine','Off');
- 第四种方案,修改
php.ini
并且输出swoole.enable_coroutine = 'Off'
phpinfo()
得到如下截图但还是报同样的错误:Uncaught Swoole\Error: must be forked outside the coroutine
提问
难道就不能在nginx
+php-fpm
中使用swoole
的进程管理吗?正确的写法应该是什么样的呢?
望知道的人不吝赐教,感谢!
swoole是cli模式下常驻进程程序,不支持php-fpm短生命周期模式