Piwik\SettingsServer::getMemoryLimitValue PHP Method

getMemoryLimitValue() public static method

Prior to PHP 5.2.1, or on Windows, --enable-memory-limit is not a compile-time default, so ini_get('memory_limit') may return false.
See also: http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
public static getMemoryLimitValue ( ) : integer | boolean
return integer | boolean memory limit in megabytes, or false if there is no limit
    public static function getMemoryLimitValue()
    {
        if (($memory = ini_get('memory_limit')) > 0) {
            // handle shorthand byte options (case-insensitive)
            $shorthandByteOption = substr($memory, -1);
            switch ($shorthandByteOption) {
                case 'G':
                case 'g':
                    return substr($memory, 0, -1) * 1024;
                case 'M':
                case 'm':
                    return substr($memory, 0, -1);
                case 'K':
                case 'k':
                    return substr($memory, 0, -1) / 1024;
            }
            return $memory / 1048576;
        }
        // no memory limit
        return false;
    }

Usage Example

Example #1
0
 public function execute()
 {
     $label = $this->translator->translate('Installation_SystemCheckMemoryLimit');
     SettingsServer::raiseMemoryLimitIfNecessary();
     $memoryLimit = SettingsServer::getMemoryLimitValue();
     $comment = $memoryLimit . 'M';
     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));
 }
All Usage Examples Of Piwik\SettingsServer::getMemoryLimitValue