You’ll see this during a large import, a report that reads a whole table, image processing, or in WordPress with heavy plugins. Every PHP script has a memory cap set by memory_limit, and that cap applies to one process, not to the whole account.
What the error means
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/user/app/Export.php on line 58
- 134217728 bytes: the current limit in bytes.
- tried to allocate 20480 bytes: the last chunk the script asked for and couldn’t get.
- Path and line: where it stopped, usually inside the loop or function collecting the data.
| Bytes | Megabytes |
|---|---|
| 67108864 | 64M |
| 134217728 | 128M |
| 268435456 | 256M |
| 536870912 | 512M |
Common causes
- Loading every row of a big table at once, such as
SELECT *orModel::all()in Laravel. - Reading a big file whole with
file_get_contents()instead of line by line. - Processing high-resolution images.
- An endless loop or runaway recursion that keeps adding data.
- Heavy WordPress plugins; see memory exhausted in WordPress.
- Composer while installing packages, which has its own page: Composer memory limit.
- A low
memory_limitsuch as 64M.
How to fix it
- Locate the code from the path and line in the message; the full text is in cPanel under Metrics › Errors.
- Raise the limit in the panel: open Software › Select PHP Version, go to Options and set
memory_limitto 256M or 512M. Or in Software › MultiPHP INI Editor, pick the domain and change the value. More on php.ini. - Other ways to set it:
# in .htaccess
php_value memory_limit 256M
// at the top of one specific script
ini_set('memory_limit', '256M');
# for a single command-line run
php -d memory_limit=512M artisan import:products
- If the error comes back at the new number, fix the code: process data in batches instead of loading it all. In Laravel:
// instead of User::all(), which loads every row
User::chunk(500, function ($users) {
foreach ($users as $user) {
// process each user
}
});
// or one record at a time
foreach (User::lazy() as $user) {
// ...
}
For a big CSV, read it line by line:
$fh = fopen('products.csv', 'r');
while (($row = fgetcsv($fh)) !== false) {
// handle the row
}
fclose($fh);
- Measure usage to see where it climbs:
echo round(memory_get_peak_usage(true) / 1048576) . " MB\n";
Prevention
- Avoid
all()andSELECT *on tables that grow over time; use pagination and batches. - Move heavy jobs such as exports and imports to cron or queues, not page requests.
- Check memory use after shipping any feature that handles a lot of data.
On ArabyHost
You can set memory_limit per site in cPanel and choose PHP 8.1, 8.2 or 8.3. Keep in mind that memory_limit caps a single process, while each account also has a total memory limit under LVE. If your processes together hit the account limit, you’ll see an error such as 508 Resource Limit Reached instead of this message, so raising memory_limit doesn’t add account memory. On AI/Developer plans you get SSH to run heavy jobs from the command line, and the Araby AI assistant reads the error log and points to the code responsible.
FAQ
How many MB is 134217728 bytes?
128 MB, since a megabyte here is 1048576 bytes. 268435456 bytes is 256 MB and 536870912 bytes is 512 MB.
Should I set memory_limit to -1?
Not on a website. -1 removes the limit, so a broken script can eat all of the account's memory and slow every site on it. Use a fixed value such as 256M or 512M.
Why does "tried to allocate" show such a small number?
It's only the last request that didn't fit, not the cause. Memory filled up gradually before it, so look for the code that accumulates a lot of data in memory.