SocketIoCommand::worker()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace yiicod\socketio\commands;
4
5
use Symfony\Component\Process\Process;
6
use yiicod\cron\commands\DaemonController;
7
use yiicod\socketio\Broadcast;
8
9
/**
10
 * Class SocketIoCommand
11
 * Run this daemon for listen socketio. Don't forget about run npm install in the folder "server".
12
 *
13
 * @package yiicod\socketio\commands
14
 */
15
class SocketIoCommand extends DaemonController
16
{
17
    use CommandTrait;
18
19
    /**
20
     * Daemon name
21
     *
22
     * @return string
23
     */
24
    protected function daemonName(): string
25
    {
26
        return 'socket.io';
27
    }
28
29
    /**
30
     * SocketOI worker
31
     */
32
    public function worker()
33
    {
34
        $process = $this->nodejs();
35
        $process->disableOutput();
36
        $process->start();
37
38
        // Save node proccess pid
39
        $this->addPid($process->getPid());
40
41
//        // Init connection for each channel
42
//        foreach (Broadcast::channels() as $channel) {
43
//            var_dump($channel);
44
//            Broadcast::publish($channel, ['name' => __CLASS__]);
45
//        }
46
//        $process->setTimeout(360000);
47
//        $process->setIdleTimeout(360000);
48
//        $process->wait(function ($type, $buffer) {
49
//            if (Process::ERR === $type) {
50
//                echo 'ERR > ' . $buffer;
51
//            } else {
52
//                echo 'OUT > ' . $buffer;
53
//            }
54
//        });
55
        while ($process->isRunning()) {
56
            $this->predis();
57
        }
58
    }
59
}
60