From 8a273e01e9f07aaf22e1f00457c3c6edd630a2f3 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 9 Apr 2024 08:47:01 +0200 Subject: [PATCH] Allow memory_limit to be configurable --- CHANGELOG.md | 2 ++ config/container.php | 2 ++ data/infra/php.ini | 1 - docker/config/php.ini | 1 - module/Core/src/Config/EnvVars.php | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1315d1..716f8787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this This allows for a better traceability, as the logs generated during those jobs will have a matching UUID as the logs generated during the request the triggered the job. +* [#2087](https://github.com/shlinkio/shlink/issues/2087) Allow `memory_limit` to be configured via the new `MEMORY_LIMIT` env var. + ### Deprecated * *Nothing* diff --git a/config/container.php b/config/container.php index 5d263173..bfab7763 100644 --- a/config/container.php +++ b/config/container.php @@ -12,6 +12,8 @@ chdir(dirname(__DIR__)); require 'vendor/autoload.php'; +// Set a default memory limit, but allow custom values +ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv('512M')); // This is one of the first files loaded. Configure the timezone here date_default_timezone_set(EnvVars::TIMEZONE->loadFromEnv(date_default_timezone_get())); diff --git a/data/infra/php.ini b/data/infra/php.ini index 64838d11..46ad43bb 100644 --- a/data/infra/php.ini +++ b/data/infra/php.ini @@ -1,6 +1,5 @@ display_errors=On error_reporting=-1 -memory_limit=-1 log_errors_max_len=0 zend.assertions=1 assert.exception=1 diff --git a/docker/config/php.ini b/docker/config/php.ini index 248e508d..f6c718d0 100644 --- a/docker/config/php.ini +++ b/docker/config/php.ini @@ -1,4 +1,3 @@ log_errors_max_len=0 zend.assertions=1 assert.exception=1 -memory_limit=512M diff --git a/module/Core/src/Config/EnvVars.php b/module/Core/src/Config/EnvVars.php index e5df9532..bae68e84 100644 --- a/module/Core/src/Config/EnvVars.php +++ b/module/Core/src/Config/EnvVars.php @@ -71,6 +71,7 @@ enum EnvVars: string case REDIRECT_APPEND_EXTRA_PATH = 'REDIRECT_APPEND_EXTRA_PATH'; case TIMEZONE = 'TIMEZONE'; case MULTI_SEGMENT_SLUGS_ENABLED = 'MULTI_SEGMENT_SLUGS_ENABLED'; + case MEMORY_LIMIT = 'MEMORY_LIMIT'; public function loadFromEnv(mixed $default = null): mixed {