Completed
Pull Request — master (#444)
by Yanick
04:28
created

LiteSpeedProxy::stop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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