dream_high1026 2017-03-30 00:32
浏览 106
已采纳

使用Supervisor运行棘轮腹板并在laravel中排队

I have made an artisan command to run a websockets on some port like below

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();
    }
}

I can run those sockets easily running an artisan command like below

php artisan run:socket 8181
php artisan run :socket 8182

I need to deploy it on a production server where thousand of devices are connected on that web sockets . I tried supervisor to daemonize the process but no luck

My conf file looks like below

[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

I realised both port 8181 and 8182 are free and are not receiving any messages.

When I tried sudo service supervisorctl I saw all process have uptime 0:00:00 and different pids

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

Is there anything I missed?

  • 写回答

1条回答 默认 最新

  • douji1853 2017-03-30 23:55
    关注

    I managed to fix it by making seperate process on supervisor

    1. Manage queue

    In /etc/supervisord/conf.d/ create 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
    

    Give it execute permissions: chmod +x laravel_queue.conf

    Now update Supervisor with: sudo supervisorctl reread. And start using those changes with: sudo supervisorctl update.

    1. socket Listener

    In /etc/supervisord/conf.d/ create 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
    

    Give it execute permissions: chmod +x socket.conf

    Now update Supervisor with: sudo supervisorctl reread. And start using those changes with: sudo supervisorctl update.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历