Skip to content

Commit a44843c

Browse files
author
rok
committed
adding support for php memory limit
1 parent 24de386 commit a44843c

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM php:7.3-alpine
22

33
LABEL maintainer="ipunkt Business Solutions <[email protected]>" \
4-
version.image="v4.0" \
4+
version.image="v4.1" \
55
version.php=$PHP_VERSION \
66
description="A supervisor configured to run with laravel artisan queue:work or artisan horizon command"
77

@@ -19,6 +19,7 @@ WORKDIR /etc/supervisor/conf.d
1919
# Use local configuration
2020
COPY laravel-worker.conf.tpl /etc/supervisor/conf.d/laravel-worker.conf.tpl
2121
COPY laravel-horizon.conf.tpl /etc/supervisor/conf.d/laravel-horizon.conf.tpl
22+
COPY custom-php.ini.tpl /opt/etc/custom-php.ini.tpl
2223

2324
# Copy scripts
2425
COPY init.sh /usr/local/bin/init.sh

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ The default queue name in laravel is called `default`. So we configured the `QUE
1010

1111
If you want to use [Laravel Horizon](https://laravel.com/docs/horizon) then you have to set the environment `LARAVEL_HORIZON` to `true`. By default it is `false`.
1212

13+
Since version v4.1 is it possible to modify the php memory limit. The environment variable `PHP_MEMORY_LIMIT` is by default set to `512` (MB). For unlimited memory usage just set it to `-1`. The queue worker command will also be called with the memory limit given to this value to be consistent.
14+
15+
For Laravel Horizon you have to configure your memory limit in your `horizon.php` configuration. The default php memory limit has to set within the container by setting `PHP_MEMORY_LIMIT` as well.
16+
1317

1418
## Docker Images
1519

@@ -18,4 +22,5 @@ If you want to use [Laravel Horizon](https://laravel.com/docs/horizon) then you
1822
| 7.0 | ipunktbs/laravel-queue-worker:php7.0-v1.0 |
1923
| 7.1 | ipunktbs/laravel-queue-worker:php7.1-v2.0 |
2024
| 7.2 | ipunktbs/laravel-queue-worker:php7.2-v3.0 |
21-
| 7.3 | ipunktbs/laravel-queue-worker:php7.3-v4.0 |
25+
| 7.3 | ipunktbs/laravel-queue-worker:php7.3-v4.0 - deprecated |
26+
| 7.3 | ipunktbs/laravel-queue-worker:php7.3-v4.1 - recommended |

custom-php.ini.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
memory_limit=%%MEMORY_LIMIT%%

init.sh

+5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ if [ -z "$LARAVEL_HORIZON" ]; then
1212
LARAVEL_HORIZON=false
1313
fi
1414

15+
PHP_MEMORY_LIMIT=${PHP_MEMORY_LIMIT:-512}
16+
sed -e "s~%%MEMORY_LIMIT%%~${PHP_MEMORY_LIMIT}m~" \
17+
/opt/etc/custom-php.ini.tpl > /usr/local/etc/php/conf.d/custom-php.ini
18+
1519
if [ "$LARAVEL_HORIZON" = false ]; then
1620
sed -e "s~%%QUEUE_CONNECTION%%~$QUEUE_CONNECTION~" \
1721
-e "s~%%QUEUE_NAME%%~$QUEUE_NAME~" \
22+
-e "s~%%MEMORY_LIMIT%%~$PHP_MEMORY_LIMIT~" \
1823
/etc/supervisor/conf.d/laravel-worker.conf.tpl > /etc/supervisor/supervisord.conf
1924
fi
2025

laravel-worker.conf.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ nodaemon=true
33

44
[program:laravel-worker]
55
process_name=%(program_name)s_%(process_num)02d
6-
command=php /var/www/app/artisan queue:work %%QUEUE_CONNECTION%% --queue=%%QUEUE_NAME%%
6+
command=php /var/www/app/artisan queue:work %%QUEUE_CONNECTION%% --queue=%%QUEUE_NAME%% --memory=%%MEMORY_LIMIT%%
77
autostart=true
88
autorestart=true
99
numprocs=1

0 commit comments

Comments
 (0)