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... 提到的一些解决方案都试过了,如:

  1. 使用如下方案报错:
    PHP Fatal error: swoole_async_set(): eventLoop has already been created. unable to change settings in xxx .
    swoole_async_set([
     'enable_coroutine' => false
    ]);
  2. 第二种方案报错:must be forked outside the coroutine
    \Swoole\Coroutine::set(['enable_coroutine' => false]);
  3. 第三种方案报错:Uncaught Swoole\Error: must be forked outside the coroutine
    ini_set('swoole.enable_coroutine','Off');
  4. 第四种方案,修改php.ini
    swoole.enable_coroutine = 'Off'
    并且输出phpinfo()得到如下截图但还是报同样的错误:Uncaught Swoole\Error: must be forked outside the coroutine
    must be forked outside the coroutine

提问

难道就不能在nginx+php-fpm中使用swoole的进程管理吗?正确的写法应该是什么样的呢?
望知道的人不吝赐教,感谢!

最佳答案

swoole是cli模式下常驻进程程序,不支持php-fpm短生命周期模式

3年前 评论
so_easy (楼主) 3年前
Tidel 3年前
讨论数量: 2

swoole是cli模式下常驻进程程序,不支持php-fpm短生命周期模式

3年前 评论
so_easy (楼主) 3年前
Tidel 3年前
CodingHePing

一个是常驻内存的,一个是fpm模式的

3年前 评论
so_easy (楼主) 3年前
CodingHePing (作者) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!