[英]Using Supervisor to run ratchet websockets and queue in laravel
I have made an artisan command to run a websockets on some port like below 我做了一个工匠命令,在下面的某个端口上运行一个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();
}
}
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 我的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
I realised both port 8181 and 8182 are free and are not receiving any messages. 我意识到端口8181和8182都是免费的,没有收到任何消息。
When I tried sudo service supervisorctl
I saw all process have uptime 0:00:00 and different pids 当我尝试
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
Is there anything I missed? 我错过了什么吗?
I managed to fix it by making seperate process on supervisor
我设法通过在主管上进行单独的处理来解决它
In /etc/supervisord/conf.d/ create laravel_queue.conf: 在/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
Give it execute permissions: chmod +x laravel_queue.conf 赋予它执行权限:chmod + x laravel_queue.conf
Now update Supervisor with: sudo supervisorctl reread. 现在更新Supervisor:sudo supervisorctl reread。 And start using those changes with: sudo supervisorctl update.
并开始使用以下更改:sudo supervisorctl update。
In /etc/supervisord/conf.d/ create socket.conf: 在/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
Give it execute permissions: chmod +x socket.conf 赋予它执行权限:chmod + x socket.conf
Now update Supervisor with: sudo supervisorctl reread. 现在更新Supervisor:sudo supervisorctl reread。 And start using those changes with: sudo supervisorctl update.
并开始使用以下更改:sudo supervisorctl update。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.