-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNodeJsServerCommand.php
More file actions
71 lines (60 loc) · 1.81 KB
/
NodeJsServerCommand.php
File metadata and controls
71 lines (60 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace SfCod\SocketIoBundle\Command;
use SfCod\SocketIoBundle\Service\Worker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Class WorkSocketIoCommand
* Socketio worker. Use pm2 (http://pm2.keymetrics.io/) for fork command.
*
* @package yiicod\socketio\commands
*/
class NodeJsServerCommand extends Command
{
/**
* @var Worker
*/
protected $worker;
/**
* NodeJsServerCommand constructor.
*/
public function __construct(Worker $worker)
{
$this->worker = $worker;
parent::__construct();
}
/**
* Configure command.
*/
protected function configure()
{
parent::configure();
$this->setName('socket-io:node-js-server')
->setDescription('Work node-js server.')
->addOption('server', null, InputArgument::OPTIONAL, 'SocketIo server.', null)
->addOption('ssl', null, InputArgument::OPTIONAL, 'SSL certificate config.', null);
}
/**
* Execute command.
*
* @return int|void|null
*
* @throws \Exception
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->success(sprintf('Worker daemon has been started.'));
$process = $this->worker->nodeJs(
$input->getOption('server') ?? getenv('SOCKET_IO_WS_SERVER'),
$input->getOption('ssl') ?? getenv('SOCKET_IO_SSL') ? getenv('SOCKET_IO_SSL') : ''
);
$process->setIdleTimeout(false);
$process->setTimeout(null);
$process->run();
return 0;
}
}