/** * Check php's memory limit * LESS compilation uses a fair amount of memory */ private function CheckMemory() { $checkValue = ini_get('memory_limit'); $expected = '16M+ or Adjustable'; echo '<tr><td>'; echo '<a href="http://php.net/manual/ini.core.php#ini.memory-limit" target="_blank">'; echo 'Memory Limit'; echo '</a>'; echo '</td>'; // adjustable if (@ini_set('memory_limit', '96M') !== false) { $this->StatusRow('passed', 'Adjustable', $expected); return; } // cant check memory if (!$checkValue) { $this->StatusRow('passed_orange', '???', $expected); return; } $byte_value = \gp\tool::getByteValue($checkValue); $mb_16 = \gp\tool::getByteValue('16M'); if ($byte_value > 100663296) { $this->StatusRow('passed', $checkValue, $expected); } elseif ($byte_value >= $mb_16) { $this->StatusRow('passed_orange', $checkValue, $expected); } else { $this->StatusRow('failed', $checkValue, $expected); $this->passed = false; } }
/** * Attempt to increase php's memory limit using the current memory used and the post_max_size value * Generally speaking, memory_limit should be larger than post_max_size http://php.net/manual/en/ini.core.php * @static */ static function AdjustMemoryLimit() { //get memory limit in bytes $limit = @ini_get('memory_limit') or '8M'; $limit = \gp\tool::getByteValue($limit); //get memory usage or use a default value if (function_exists('memory_get_usage')) { $memoryUsed = memory_get_usage(); } else { $memoryUsed = 3 * 1048576; //sizable buffer 3MB } //since imageHeight and imageWidth aren't always available //use post_max_size to figure maximum memory limit $max_post = @ini_get('post_max_size') or '8M'; //defaults to 8M $max_post = \gp\tool::getByteValue($max_post); $needed = $max_post + $memoryUsed; if ($limit < $needed) { @ini_set('memory_limit', $needed); } }
/** * Handle the processing of multiple less files into css * * @return mixed Compiled css string or false * */ static function ParseLess(&$less_files) { global $dataDir; $compiled = false; // don't use less if the memory limit is less than 64M $limit = @ini_get('memory_limit'); if ($limit) { $limit = \gp\tool::getByteValue($limit); //if less than 64M, disable less compiler if we can't increase if ($limit < 67108864 && @ini_set('memory_limit', '96M') === false) { if (\gp\tool::LoggedIn()) { msg('LESS compilation disabled. Please increase php\'s memory_limit'); } return false; //if less than 96M, try to increase } elseif ($limit < 100663296) { @ini_set('memory_limit', '96M'); } } //compiler options $options = array(); //prepare the compiler includeFile('thirdparty/less.php/Less.php'); $parser = new \Less_Parser($options); $import_dirs[$dataDir] = \gp\tool::GetDir('/'); $parser->SetImportDirs($import_dirs); $parser->cache_method = 'php'; $parser->SetCacheDir($dataDir . '/data/_cache'); // combine files try { foreach ($less_files as $less) { //treat as less markup if there are newline characters if (strpos($less, "\n") !== false) { $parser->Parse($less); continue; } // handle relative and absolute paths if (!empty($dataDir) && strpos($less, $dataDir) === false) { $relative = $less; $less = $dataDir . '/' . ltrim($less, '/'); } else { $relative = substr($less, strlen($dataDir)); } $parser->ParseFile($less, \gp\tool::GetDir(dirname($relative))); } $compiled = $parser->getCss(); } catch (Exception $e) { if (\gp\tool::LoggedIn()) { msg('LESS Compile Failed: ' . $e->getMessage()); } return false; } // significant difference in used memory 15,000,000 -> 6,000,000. Max still @ 15,000,000 if (function_exists('gc_collect_cycles')) { gc_collect_cycles(); } $less_files = $parser->allParsedFiles(); return $compiled; }
public static function Max_File_Size() { $value = ini_get('upload_max_filesize'); if (empty($value)) { return; } $max = \gp\tool::getByteValue($value); if ($max !== false) { echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $max . '" />'; } }