php - 使用 Supervisor 在 Laravel 中运行 Ratchet websockets 和队列

标签 php laravel supervisord ratchet phpwebsocket

我已经制作了一个工匠命令来在如下所示的某个端口上运行 websockets

class webSockets extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'run:socket {port?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Run websockets for specified port';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(RedisInterface $redis)
    {
        $this->redis=$redis;
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
       $port = $this->argument('port');
       if($port=='8182') {
            $server = IoServer::factory(
                         new SocketController($this->redis),$port
                    );
       }
       else if($port=='8181'){
            $server = IoServer::factory(
                         new Socket1Controller($this->redis),$port
                    );
       }



       $server->run();
    }
}

我可以轻松地运行这些套接字,运行如下所示的工匠命令
php artisan run:socket 8181
php artisan run :socket 8182

我需要将它部署在生产服务器上,在该服务器上,该网络套接字连接了数千台设备。 我尝试使用主管来守护进程,但没有成功

我的 conf 文件如下所示
[program:ratchet]
command                 = php /var/www/v3 artisan run:socket 8181;php /var/www/v3 artisan run:socket 8182
process_name            = Ratchet
numprocs                = 1
autostart               = true
autorestart             = true
stdout_logfile          = ./logs/info.log
stderr_logfile          = ./logs/error.log

我意识到端口 8181 和 8182 都是免费的,并且没有收到任何消息。

当我尝试 sudo service supervisorctl我看到所有进程都有正常运行时间 0:00:00 和不同的 pid
laravel_queue                    RUNNING   pid 62246, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62245, uptime 0:00:00
supervisor> status
laravel_queue                    RUNNING   pid 62305, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62304, uptime 0:00:00
supervisor> status
laravel_queue                    RUNNING   pid 62419, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62418, uptime 0:00:00
supervisor> status
laravel_queue                    RUNNING   pid 62553, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62552, uptime 0:00:00
supervisor> status
laravel_queue                    RUNNING   pid 62689, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62688, uptime 0:00:00
supervisor> status
laravel_queue                    RUNNING   pid 62819, uptime 0:00:00
ratchet:Ratchet                  RUNNING   pid 62818, uptime 0:00:00
supervisor> status

有什么我错过的吗?

最佳答案

I managed to fix it by making seperate process on supervisor


  • 管理队列

  • 在/etc/supervisord/conf.d/中创建laravel_queue.conf:
    [program:laravel_queue]
    command= php artisan queue:listen redis --timeout=7200
    directory=/var/www/gpsv3
    stderr_logfile=/var/www/gpsv3/storage/logs/laraqueue.err.log
    stdout_logfile=/var/www/gpsv3/storage/logs/laraqueue.out.log
    redirect_stderr=true
    

    给它执行权限:chmod +x laravel_queue.conf

    现在更新主管: sudo supervisorctl reread。并开始使用这些更改:sudo supervisorctl update。
  • 套接字监听器

  • 在/etc/supervisord/conf.d/中创建socket.conf:
    [program:socket]
    command= php artisan run:socket 8182
    directory=/var/www/gpsv3
    stderr_logfile=/var/www/gpsv3/storage/logs/socket.err.log
    stdout_logfile=/var/www/gpsv3/storage/logs/socket.out.log
    redirect_stderr=true
    

    给它执行权限:chmod +x socket.conf

    现在更新主管: sudo supervisorctl reread。并开始使用这些更改:sudo supervisorctl update。

    关于php - 使用 Supervisor 在 Laravel 中运行 Ratchet websockets 和队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43106480/

    相关文章:

    php - 在 PostgreSQL 中存储类似 BLOB 的数据

    php - 为什么 PHPExcel 在 Kohana 中使用时会尝试从 Excel 文件名创建类名?

    mysql - Laravel 的数据库查询生成器

    php - Laravel 5.5 有条件地添加验证规则

    python - Supervisor - 无法以 root 或用户身份启动 supervisorctl(用户在配置中设置)

    php - 如何实现分布式文件上传解决方案?

    javascript - 在注册页面和感谢页面之间添加一个加载页面

    php - 无法显示 Laravel 欢迎页面

    记录Supervisord

    supervisord - 重启服务主管