# PHP memory limit vs your plan's RAM ("Allowed memory size exhausted")

> Fix the "Allowed memory size exhausted" PHP error, and understand the difference between PHP's memory_limit and your hosting plan's RAM.

Source: https://helpcenter.ruachost.com/developers/php/resolving-the-allowed-memory-size-exhausted-php-error-message/

## The error

```
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)
```

This means one PHP script tried to use more memory than its **`memory_limit`** allows. The number is in bytes: 134217728 bytes is 128 MB, 268435456 is 256 MB, and 536870912 is 512 MB.

## memory_limit and your plan's RAM are different things

| | PHP `memory_limit` | Your plan's RAM |
| --- | --- | --- |
| **What it limits** | The memory **one PHP script** can use | The memory **your whole account** can use at the same time, across all visitors, scripts and cron jobs |
| **Where it's set** | cPanel → **Select PHP Version → Options** | Your hosting plan |
| **Default** | 512 MB | Depends on your plan |
| **Error you see** | "Allowed memory size of … bytes exhausted" | "508 Resource Limit Is Reached", or the site slows down or shows 503 errors |

So raising `memory_limit` lets a single heavy script run, but it doesn't give your account more RAM. If your site has many visitors at once, each one runs its own PHP process, and together they share your plan's RAM.

## Fix "Allowed memory size exhausted"

### 1. Raise memory_limit

1. In cPanel, open **Select PHP Version** and click the **Options** tab.
2. Set **`memory_limit`** higher, for example **1G**. You can choose up to 2G.

Changes apply straight away. See [Changing your PHP version and settings](https://helpcenter.ruachost.com/cpanel/software/changing-php-versions-and-settings-using-php-selector/).

### 2. Check your app's own limit

Some apps set their own lower limit, which overrides the server setting.

- **WordPress:** look in `wp-config.php` for `WP_MEMORY_LIMIT` or `WP_MAX_MEMORY_LIMIT`, and raise or remove them:

  ```php
  define( 'WP_MEMORY_LIMIT', '512M' );
  ```

- **Other apps:** search your files for `ini_set('memory_limit'` or `php_value memory_limit` in `.htaccess`.

### 3. If the error continues at a high limit

If a script still runs out of memory at 1 GB or more, it's usually a problem in the code, not the limit:

- A plugin, theme or import is loading too much data at once. Check the [error log](https://helpcenter.ruachost.com/developers/php/enabling-php-error-logging/) to see which file is named, then update or replace that plugin.
- A loop never ends. Higher limits only make it fail later.
- Very large imports or image processing: split them into smaller batches.

## Fix "Resource Limit Is Reached"

This means your **account** reached your plan's RAM, CPU or process limit. Raising `memory_limit` won't fix it and can make it worse. Instead:

- Turn on caching, for example LiteSpeed Cache for WordPress, so fewer pages run PHP.
- Block bad bots and remove plugins you don't use.
- Check your usage in cPanel under **Resource Usage**.

See [Help! Resource limit has been reached](https://helpcenter.ruachost.com/getting-started/website-troubleshooting/help-resource-limit-has-been-reached/). If your site has outgrown its plan, upgrade your plan or move to a [Managed VPS](https://ruachost.com/vps).
