Skip to content

Commit

Permalink
Merge pull request #156 from clue-labs/memory_limit
Browse files Browse the repository at this point in the history
Add instructions to increase PHP's default `memory_limit`
  • Loading branch information
SimonFrings authored May 13, 2022
2 parents 75c551f + 7f139f6 commit 440d40d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 28 additions & 1 deletion docs/best-practices/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,32 @@ or `[::]` IPv6 address like this:
$ X_LISTEN=0.0.0.0:8080 php public/index.php
```

### Memory limit

X is carefully designed to minimize memory usage. Depending on your application
workload, it may need anywhere from a few kilobytes to a couple of megabytes per
request. Once the request is completely handled, used memory will be freed again.
Under load spikes, memory may temporarily increase to handle concurrent requests.
PHP can handle this load just fine, but many default setups use a rather low
memory limit that is more suited for single requests only.

```
Fatal error: Allowed memory size of 134217728 bytes exhausted […]
```

When using the built-in web server, we highly recommend increasing the memory
limit to match your concurrency workload. On Ubuntu- or Debian-based systems,
you may change your PHP configuration like this:

```bash
$ sudoedit /etc/php/8.1/cli/php.ini
```

```diff title="/etc/php/8.1/cli/php.ini"
- memory_limit = 128M
+ memory_limit = -1
```

### Systemd

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

WORKDIR /app/
COPY public/ public/
Expand Down
3 changes: 2 additions & 1 deletion tests/Dockerfile-production
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN apk --no-cache add ${PHPIZE_DEPS} libev \
&& pecl install ev \
&& docker-php-ext-enable ev \
&& docker-php-ext-install sockets \
&& apk del ${PHPIZE_DEPS}
&& apk del ${PHPIZE_DEPS} \
&& echo "memory_limit = -1" >> "$PHP_INI_DIR/conf.d/acme.ini"

WORKDIR /app/
COPY public/ public/
Expand Down

0 comments on commit 440d40d

Please sign in to comment.