diff --git a/library/Icinga/File/Pdf.php b/library/Icinga/File/Pdf.php index 242e2ddd8..912109b02 100644 --- a/library/Icinga/File/Pdf.php +++ b/library/Icinga/File/Pdf.php @@ -8,6 +8,7 @@ use Dompdf\Dompdf; use Dompdf\Options; use Icinga\Application\Icinga; use Icinga\Exception\ProgrammingError; +use Icinga\Util\Format; use Icinga\Web\Hook; use Icinga\Web\Url; @@ -45,8 +46,17 @@ class Pdf public function renderControllerAction($controller) { $this->assertNoHeadersSent(); - ini_set('memory_limit', '384M'); - ini_set('max_execution_time', 300); + + $memLimit = 512 * 1024 ** 2; + if (Format::unpackShorthandBytes(ini_get('memory_limit')) < $memLimit) { + ini_set('memory_limit', $memLimit); + } + + $maxExecTime = 300; + if ((int) ini_get('max_execution_time') < $maxExecTime) { + ini_set('max_execution_time', $maxExecTime); + } + $viewRenderer = $controller->getHelper('viewRenderer'); $controller->render( $viewRenderer->getScriptAction(), diff --git a/library/Icinga/Util/Format.php b/library/Icinga/Util/Format.php index b43be49cc..f3e682128 100644 --- a/library/Icinga/Util/Format.php +++ b/library/Icinga/Util/Format.php @@ -4,8 +4,6 @@ namespace Icinga\Util; use DateTime; -use Icinga\Date\DateFormatter; -use Icinga\Exception\ProgrammingError; class Format { @@ -141,4 +139,37 @@ class Format return $dt->format('L') == 1; } + + /** + * Unpack shorthand bytes PHP directives to bytes + * + * @param string $subject + * + * @return int + */ + public static function unpackShorthandBytes($subject) + { + $base = (int) $subject; + + if ($base <= -1) { + return INF; + } + + switch (strtoupper($subject[strlen($subject) - 1])) { + case 'K': + $multiplier = 1024; + break; + case 'M': + $multiplier = 1024 ** 2; + break; + case 'G': + $multiplier = 1024 ** 3; + break; + default: + $multiplier = 1; + break; + } + + return $base * $multiplier; + } }