Skip to content

Commit 440d40d

Browse files
authored
Merge pull request #156 from clue-labs/memory_limit
Add instructions to increase PHP's default `memory_limit`
2 parents 75c551f + 7f139f6 commit 440d40d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

docs/best-practices/deployment.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ or `[::]` IPv6 address like this:
277277
$ X_LISTEN=0.0.0.0:8080 php public/index.php
278278
```
279279

280+
### Memory limit
281+
282+
X is carefully designed to minimize memory usage. Depending on your application
283+
workload, it may need anywhere from a few kilobytes to a couple of megabytes per
284+
request. Once the request is completely handled, used memory will be freed again.
285+
Under load spikes, memory may temporarily increase to handle concurrent requests.
286+
PHP can handle this load just fine, but many default setups use a rather low
287+
memory limit that is more suited for single requests only.
288+
289+
```
290+
Fatal error: Allowed memory size of 134217728 bytes exhausted […]
291+
```
292+
293+
When using the built-in web server, we highly recommend increasing the memory
294+
limit to match your concurrency workload. On Ubuntu- or Debian-based systems,
295+
you may change your PHP configuration like this:
296+
297+
```bash
298+
$ sudoedit /etc/php/8.1/cli/php.ini
299+
```
300+
301+
```diff title="/etc/php/8.1/cli/php.ini"
302+
- memory_limit = 128M
303+
+ memory_limit = -1
304+
```
305+
280306
### Systemd
281307

282308
So far, we're manually executing the application server on the command line and
@@ -513,7 +539,8 @@ be achieved by using a `Dockerfile` with the following contents:
513539
&& pecl install ev \
514540
&& docker-php-ext-enable ev \
515541
&& docker-php-ext-install sockets \
516-
&& apk del ${PHPIZE_DEPS}
542+
&& apk del ${PHPIZE_DEPS} \
543+
&& echo "memory_limit = -1" >> "$PHP_INI_DIR/conf.d/acme.ini"
517544

518545
WORKDIR /app/
519546
COPY public/ public/

tests/Dockerfile-production

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RUN apk --no-cache add ${PHPIZE_DEPS} libev \
1515
&& pecl install ev \
1616
&& docker-php-ext-enable ev \
1717
&& docker-php-ext-install sockets \
18-
&& apk del ${PHPIZE_DEPS}
18+
&& apk del ${PHPIZE_DEPS} \
19+
&& echo "memory_limit = -1" >> "$PHP_INI_DIR/conf.d/acme.ini"
1920

2021
WORKDIR /app/
2122
COPY public/ public/

0 commit comments

Comments
 (0)