Aller au contenu

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

Ce contenu n’est pas encore disponible dans votre langue.

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

Section titled “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.

  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.

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:

    define( 'WP_MEMORY_LIMIT', '512M' );
  • Other apps: search your files for ini_set('memory_limit' or php_value memory_limit in .htaccess.

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 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.

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. If your site has outgrown its plan, upgrade your plan or move to a Managed VPS.

Cette page vous a-t-elle aidé ?