# Sizes and PHP limits

## Sizes

An app's size caps the memory each of its processes may use, and for PHP apps how many requests run at once.

| Size                 | Memory per process | PHP workers |
| -------------------- | ------------------ | ----------- |
| Small, side projects | 256 MB             | 5           |
| Medium, production   | 512 MB             | 15          |
| Large, heavy traffic | 1 GB               | 30          |

New apps start on Small, except Ruby and Java apps, which start on Medium. Change the size on the app's page at any time.

Python apps run 2, 4 or 8 web workers on Small, Medium and Large, and their Celery worker runs as many processes. Set `WEB_CONCURRENCY` in the app's environment to change the web workers.

Ruby apps run one web process on every size, since a Puma config that starts a worker per processor would outgrow it. Set `WEB_CONCURRENCY` in the app's environment to run more.

A size sets a cap, and reserves nothing, so several apps can share a server as long as what they really use fits in its memory.

## When an app runs out of memory

A process that goes past its memory is stopped and started again. If it keeps happening right after a deploy, the deploy fails with an out-of-memory message, and Coresmith emails the people who get server alerts. Pick a bigger size, or find what's using the memory.

## PHP limits

Every PHP app has four limits, on the **PHP limits** card on its page. They apply to everything the app runs in PHP: the website, queue workers, cron jobs and deploy steps. Saving a change applies it without a deploy, and requests already running finish first.

| Limit                   | New apps start at                                                                | Choices                            |
| ----------------------- | -------------------------------------------------------------------------------- | ---------------------------------- |
| Uploads up to           | 64 MB per request                                                                | 8 MB to 1 GB                       |
| Memory per process      | Half of what the size allows: 128 MB on Small, 256 MB on Medium, 512 MB on Large | 64 MB up to what the size allows   |
| Web requests stop after | 60 seconds                                                                       | 30 seconds to 5 minutes            |
| New code loads          | At each deploy for Laravel and Symfony, every 2 seconds for other PHP apps       | At each deploy, or every 2 seconds |

- **Uploads:** the limit covers the whole request. A request that arrives over a slow connection has up to 5 minutes to finish arriving.
- **Memory:** a process that needs more than its limit stops with PHP's "Allowed memory size exhausted" error.
- **Web requests:** a request that runs past its limit is stopped, even one waiting on a slow database. Queue workers and cron jobs aren't timed.
- **New code:** at each deploy is faster. Pick every 2 seconds if the app writes its own PHP files while it runs, as WordPress does when it updates plugins.
