Completed
Pull Request — master (#444)
by Yanick
03:13
created

LiteSpeedProxy::start()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
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
class LiteSpeedProxy extends AbstractProxy
15
{
16
    protected $binary = '/usr/local/lsws/bin/lswsctrl';
17
18
    protected $port = 8080;
19
20
    protected $cacheDir = '/usr/local/lsws/cachedata';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function start()
26
    {
27
        $process = $this->runCommand([
28
            $this->getBinary(),
29
            'status',
30
        ], true);
31
32
        // Already running
33
        if (false !== strpos($process->getOutput(), 'litespeed is running with PID')) {
34
            return;
35
        }
36
37
        // Starting deamonized
38
        $this->runCommand([
39
            $this->getBinary(),
40
            'start',
41
        ], true);
42
43
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function stop()
50
    {
51
        $this->runCommand([
52
            $this->getBinary(),
53
            'stop',
54
        ], true);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function clear()
61
    {
62
        $this->runCommand([
63
            'rm',
64
            '-rf',
65
            $this->getCacheDir(),
66
        ], true);
67
68
        $this->start();
69
    }
70
71
    /**
72
     * @param string $cacheDir
73
     */
74
    public function setCacheDir($cacheDir)
75
    {
76
        $this->cacheDir = $cacheDir;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getCacheDir()
83
    {
84
        return $this->cacheDir;
85
    }
86
}
87