Completed
Pull Request — master (#444)
by Yanick
04:01 queued 01:53
created

LiteSpeedProxy::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test\Proxy;
13
14
use DirectoryIterator;
15
16
class LiteSpeedProxy extends AbstractProxy
17
{
18
    protected $binary = '/usr/local/lsws/bin/lswsctrl';
19
20
    protected $port = 8080;
21
22
    protected $cacheDir = '/usr/local/lsws/cachedata';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function start()
28
    {
29
        $process = $this->runCommand([
30
            $this->getBinary(),
31
            'status',
32
        ], true);
33
34
        // Already running, restart
35
        if (false !== strpos($process->getOutput(), 'litespeed is running with PID')) {
36
            $this->runCommand([
37
                $this->getBinary(),
38
                'restart',
39
            ], true);
40
41
            return;
42
        }
43
44
        // Otherwise start
45
        $this->runCommand([
46
            $this->getBinary(),
47
            'start',
48
        ], true);
49
50
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function stop()
57
    {
58
        $this->runCommand([
59
            $this->getBinary(),
60
            'stop',
61
        ], true);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function clear()
68
    {
69
        // Runs as sudo to make sure it can be removed
70
        $this->runCommand([
71
            'rm',
72
            '-rf',
73
            $this->getCacheDir(),
74
        ], true);
75
76
        // Does not run as sudo to make sure it's created using the correct user
77
        $this->runCommand([
78
            'mkdir',
79
            '-p',
80
            $this->getCacheDir(),
81
        ]);
82
83
        $this->start();
84
    }
85
86
    /**
87
     * @param string $cacheDir
88
     */
89
    public function setCacheDir($cacheDir)
90
    {
91
        $this->cacheDir = $cacheDir;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getCacheDir()
98
    {
99
        return $this->cacheDir;
100
    }
101
}
102