public static function set($limit)
    {
        if (!is_int($limit)) throw new Kwf_Exception('Limit must be an integer');
        if ($limit <= 0) throw new Kwf_Exception('Not allowed setting memory limit to: ' . $limit);

        $currentLimit = self::convertToMegabyte(ini_get('memory_limit'));
        if ($limit < (int)$currentLimit) return false;

        $value = $limit;
        $maxLimit = self::getMaxLimit();
        if ($maxLimit > 0 && $maxLimit < $limit) {
            $value = $maxLimit;
        }

        ini_set('memory_limit', $value . 'M');
        return $limit == $value;
    }