---
title: "memory_limit"
description: "memory_limit is a PHP directive that sets the maximum RAM a single script may use. Learn how it works, typical values and how to change the limit."
url: "https://nodea.io/en/glossary/memory-limit"
lang: "en"
updated: "2026-07-13"
---

# memory\_limit

> memory\_limit is a PHP configuration directive that sets the maximum amount of RAM a single script may consume. It protects the server from a single request exhausting its resources.

**memory\_limit** is a configuration directive of the [PHP](https://nodea.io/en/glossary/php) language that sets the maximum amount of RAM a single script may consume during one request. When a script exceeds this threshold, PHP halts its execution and throws a fatal "Allowed memory size exhausted" error. This mechanism protects the server from a situation where one inefficient or malicious script would drain the entire machine's memory.

## How memory\_limit works

The value is expressed in bytes or with a unit suffix, for example *128M* or *256M*. The limit applies separately to each process handling a request — if the server processes dozens of requests in parallel, each has its own allowance, so the value must be chosen with the available RAM and the number of [PHP-FPM](https://nodea.io/en/glossary/php-fpm) processes in mind. The currently effective value can be checked in the output of the [phpinfo()](https://nodea.io/en/glossary/phpinfo) function. A setting of *-1* means no limit, which is discouraged on production servers.

## Practical application

The default 128 MB is enough for simple sites, but larger applications — Magento, stores with many plugins, importing large files or generating PDFs — may need 256 MB or more. The limit is changed in php.ini, in the PHP-FPM pool configuration, via a *php\_value* directive in the [.htaccess](https://nodea.io/en/glossary/htaccess) file (on servers with mod\_php), or with *ini\_set()* in code.

On shared hosting the upper bound of memory\_limit is set by the provider so that one customer cannot dominate the resources of a shared machine. On a VPS or dedicated server the administrator has full control over this value. It is worth remembering that raising the limit treats the symptom rather than the cause — if a script uses excessive memory, a better solution is to [optimize](https://nodea.io/en/glossary/optimization) it, for example by processing data in smaller chunks.

### How do you increase memory\_limit in PHP?

You can change the value in php.ini (e.g. memory\_limit = 256M), in the PHP-FPM pool configuration, via a php\_value directive in .htaccess on servers with mod\_php, or in code with ini\_set(). On shared hosting the limit is often set in the control panel, and its upper bound may be capped by the provider for performance reasons.

### What does the "Allowed memory size exhausted" error mean?

It means a PHP script tried to use more memory than memory\_limit allows. Common causes are processing very large data sets, a memory leak, or inefficient code. The fix is to optimize the script (for example by processing data in chunks) or, when justified, to raise the limit.

## Related

- [PHP](https://nodea.io/en/glossary/php)
- [PHP-FPM](https://nodea.io/en/glossary/php-fpm)
- [phpinfo](https://nodea.io/en/glossary/phpinfo)
- [.htaccess](https://nodea.io/en/glossary/htaccess)
- [Optimization](https://nodea.io/en/glossary/optimization)

---

Languages: [pl](https://nodea.pl/pl/slownik-pojec/memory-limit.md)  
Site index: [llms.txt](https://nodea.io/en/llms.txt)
