Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MemoryLimitCheck.php « Diagnostic « Diagnostics « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00c7fad6183cc53aeb9cd9b1f657f8279cbc4e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Plugins\Diagnostics\Diagnostic;

use Piwik\SettingsServer;
use Piwik\Translation\Translator;

/**
 * Check that the memory limit is enough.
 */
class MemoryLimitCheck implements Diagnostic
{
    /**
     * @var Translator
     */
    private $translator;

    /**
     * @var int
     */
    private $minimumMemoryLimit;

    public function __construct(Translator $translator, $minimumMemoryLimit)
    {
        $this->translator = $translator;
        $this->minimumMemoryLimit = $minimumMemoryLimit;
    }

    public function execute()
    {
        $label = $this->translator->translate('Installation_SystemCheckMemoryLimit');

        SettingsServer::raiseMemoryLimitIfNecessary();

        $memoryLimit = SettingsServer::getMemoryLimitValue();
        $comment = $memoryLimit . 'M';

        if(false === $memoryLimit) {
            $status = DiagnosticResult::STATUS_OK;
            $comment = $this->translator->translate('Installation_SystemCheckMemoryNoMemoryLimitSet');
        } else if ($memoryLimit >= $this->minimumMemoryLimit) {
            $status = DiagnosticResult::STATUS_OK;
        } else {
            $status = DiagnosticResult::STATUS_WARNING;
            $comment .= sprintf(
                '<br />%s<br />%s',
                $this->translator->translate('Installation_SystemCheckMemoryLimitHelp'),
                $this->translator->translate('Installation_RestartWebServer')
            );
        }

        return array(DiagnosticResult::singleResult($label, $status, $comment));
    }
}