WorkerCommand::actionPhpServer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
//namespace yiicod\socketio\commands;
4
//
5
//use yii\console\Controller;
6
//
7
///**
8
// * Class SocketIoCommand
9
// * Run this daemon for listen socketio. Don't forget about run npm install in the folder "server".
10
// *
11
// * @package yiicod\socketio\commands
12
// */
13
//class WorkerCommand extends Controller
14
//{
15
//    use CommandTrait;
16
//
17
//    /**
18
//     * @var string
19
//     */
20
//    public $defaultAction = 'work';
21
//
22
//    /**
23
//     * @var int
24
//     */
25
//    public $delay = 15;
26
//
27
//    /**
28
//     * @throws \Exception
29
//     */
30
//    public function actionWork()
31
//    {
32
//        $process = $this->nodejs();
33
//        $process->disableOutput();
34
//        $process->start();
35
//
36
//        while ($process->isRunning()) {
37
//            try {
38
//                $this->predis();
39
//            } catch (\Throwable $e) {
40
//                $process->stop(0);
41
//                die('111');
42
//                throw $e;
43
//            }
44
//        }
45
//    }
46
//
47
//
48
//    /**
49
//     * @return FileOutput
50
//     */
51
//    protected function output($text)
52
//    {
53
//        $this->stdout($text);
54
//    }
55
//}
56
57
namespace yiicod\socketio\commands;
58
59
use yii\console\Controller;
60
61
/**
62
 * Socketio server. You should run two commands: "socketio/node-js-server" and "socketio/php-server". Use pm2 as daemon manager.
63
 *
64
 * @package yiicod\socketio\commands
65
 */
66
class WorkerCommand extends Controller
67
{
68
    use CommandTrait;
69
70
    /**
71
     * @var string
72
     */
73
    public $defaultAction = 'work';
74
75
    /**
76
     * @var int
77
     */
78
    public $delay = 15;
79
80
    /**
81
     * Node js listener.
82
     *
83
     * @throws \Exception
84
     */
85
    public function actionNodeJsServer()
86
    {
87
        $process = $this->nodejs();
88
        $process->setTimeout(null);
89
        $process->setIdleTimeout(null);
90
        $process->run();
91
    }
92
93
    /**
94
     * Php listener
95
     *
96
     * @throws \Exception
97
     */
98
    public function actionPhpServer()
99
    {
100
        while (true) {
101
            $this->predis();
102
        }
103
    }
104
105
    /**
106
     * @return FileOutput
107
     */
108
    protected function output($text)
109
    {
110
        $this->stdout($text);
111
    }
112
}
113