Php fatal error allowed memory size exhausted in unknown on line 0

Ошибка — Fatal error: Allowed memory size

Ошибка Fatal error: Allowed memory size гласит о том, что вы достигли ограничения по памяти, которые у вас установлены в настройках web-сервера.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in . говорит, что 128 Мб не достаточно (число выше указано в байтах) и его нужно увеличить, либо в указанном месте решить проблему с утечкой памяти.

Решение проблемы с ограничением памяти

Есть два варианта как завершить операцию:

Первый вариант сложен и не всегда возможен. Поэтому рассматривать его не будем.

Хотя, зачастую бывает так, что сайт, например, пытается сжать очень большую картинку в другой размер (например, фото в оригинале весит 20 Мб). В этом случае просто используйте оригинальные картинки меньшего размера.

Второй вариант проще и подойдет как временное решение, до тех пор пока не найдется основной корень зла. Существует несколько способов увеличить лимит.

Читайте также:  JS в HTML

Файл php.ini

Это рекомендуемый способ, если вы имеете доступ к файлу php.ini. Данный способ не сработает на многих платных хостингах провайдер, т.к. там закрывают доступ к этому файлу, в целях безопасности. Внимание! Данный способ затронет все ваши сайты и скрипты, находящиеся на сервере.

Откройте файл php.ini и найдите там строку memory_limit:

Через .htaccess в корне сайта

Добавьте в самом начале строку php_value memory_limit 256M. Во время выполнения PHP, запишите перед тяжелыми операциями в php-файл следующую строчку

Как посмотреть, сработало ли?

Откройте в панели управления Joomla информацию о системе

Информация о системе

И найдите строку memory_limit

Строка memory_limit

Тоже самое можно сделать через команду .

Если не получилось.

В случае, если рекомендации из статьи не помогли вам (возможно хостинг не дает таких прав), то обратитесь с этим вопросом к техподдержке вашего хостинга. Если хостер отказал, то рассмотрите вариант с выполнением тяжелых операций на локальной машине. Затем результат работы перенесите на ваш продуктивный сайт в интернете.

Альтернатива

Также оптимизации по памяти можно добиться установкой APC. Он уменьшает потребление памяти в ~1,5-2 раза и ускоряет работу всего сайта в целом. Для нормальной работы Joomla + JBZoo обычно хватает 64 Мб (с серьезным запасом на будущее).

Источник

Три способа решения проблемы «Fatal error: Allowed memory size of XXX bytes exhausted»

Когда вашему скрипту не хватает оперативной памяти для его выполнения (точнее он не укладывается в объём, который ему разрешён), возникает ошибка «Allowed memory size of XXX bytes exhausted (tried to allocate YYY bytes)».

Для решения данной задачи предлагаю три варианта на выбор в зависимости от прав доступа на сервере и его конфигурации.

Варианты

Один из этих вариантов вам точно поможет.

Способ первый

В файле настроек РНР (php.ini) пишем:

Обычно для простых смертных этот файл править не дают. Всё зависит от вашего хостинг-провайдера. Да и делать вам там нечего.

Способ второй

В файле настроек сайта (.htaccess) пишем:

php_value memory_limit 100M

При определённой конфигурации сервера вы можете получить ошибку 500 — Internal Server Error.

Способ третий

В теле вашего скрипта (например, config.php) пишем:

Самый простой и безопасный ход решения проблемы. Меня выручает постоянно.

Для сайта на WordPress

В начале вашего файла конфигурации wp-config.php в корне сайта добавьте строку:

Русский разработчик со стажем. Работаю с PHP, ООП, JavaScript, Git, WordPress, Joomla, Drupal. Оптимизирую сайты под Google Page Speed, настраиваю импорты для больших магазинов на WooCommerce + WP All Import. Пишу плагины на заказ. Все мои услуги. Веду блог о разработке, дайджест в телеграмме и в ВК. Вы всегда можете нанять меня.

Спасибо, в моем случае сработал второй способ, скрипт выдавал ошибку Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 84 bytes) но увеличить обьем выделенной оперативной памяти на своем хостинге я не смог, поэтому прописав напрямую в скрипте дерективу удалось обойти ограничение и скрипт отработал отлично. Спасибо!

Источник

Troubleshooting the “PHP Fatal error: Allowed memory size exhausted”

The “allowed memory size exhausted” fatal PHP error means that a PHP script exceeded the set PHP memory limit and thus failed. This can result in 500 errors or broken functionality within a webpage.

The error will be available either in your website Nginx or OpenLiteSpeed error log and will look like this:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 10485760 bytes) in on line 370

Fortunately, this is a quick and easy fix, and below we’ll cover the two scenarios that you may encounter.

Table of Contents

Understanding the PHP Memory Limit

PHP.net breaks PHP memory_limit down like this:

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

This setting is per-script, which means that other scripts on the same page may execute like normal (since they have their own memory allocation), and only a portion of the page will be broken. In other cases, it could cause a 500 HTTP error, and the page may fail to load altogether.

More often than not, when we see this error, it’s usually due to a WordPress plugin.

How Much Should You Increase It?

Increase the memory enough to resolve the error from happening, and then simply leave it there. If it requires more than 512MB, then this is potentially problematic and you should address the issue directly within your code base (usually, it’s finding a replacement for a plugin).

Setting a high memory limit does not provide any additional benefit and can actually result in issues that are otherwise easy to avoid. By setting a high memory limit you’re allowing the possibility for poorly written code to consume all of your RAM and potentially cause performance issues across ALL of the sites on this server, and you would also be oblivious to any future code issues that may arise.

1. Website PHP Memory Limit Exhausted

GridPane sets a default size of 256MB, which is plenty for almost all use cases, even WooCommerce. This is fairly standard for the industry.

It is generally better to find and fix the code responsible for needing more memory, but you can also easily increase the PHP memory limit inside your website customizer > PHP INI settings.

To get started, navigate to the Sites page inside your account and click on the name of the website to open up the customizer. Here, you’ll find the memory setting located inside PHP > PHP INI here:

Enter the new memory limit and hit update.

Alternative Option: Set via GP-CLI

Alternatively, you can set this via GP-CLI with the following command:

gp stack php -site-mem-limit

gp stack php -site-mem-limit 512 gridpane.com

2. PHP CLI Memory Limit Exhausted

It’s far rarer to encounter this error, but it’s possible you could run into it using WP-CLI on the command line.

Step 1. Check php.ini used

Connect to your server via SSH and run the following:

Step 2.1 Nginx

On Nginx, the output will look as follows, and we’re specifically looking for the highlighted line:

OS: Linux 4.15.0-197-generic #208-Ubuntu SMP Tue Nov 1 17:23:37 UTC 2022 x86_64 Shell: /bin/bash PHP binary: /usr/bin/php8.0 PHP version: 8.0.25 php.ini used: /etc/php/8.0/cli/php.ini MySQL binary: /usr/bin/mysql MySQL version: mysql Ver 8.0.30-22 for Linux on x86_64 (Percona Server (GPL), Release '22', Revision '7e301439b65') SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /root WP-CLI packages dir: /root/.wp-cli/packages/ WP-CLI cache dir: /root/.wp-cli/cache WP-CLI global config: WP-CLI project config: WP-CLI version: 2.7.1

The current CLI PHP version across GridPane servers is 8.0 as above. We can increase the memory_limit by editing this file with:

Step 2.2 OpenLiteSpeed

On OpenLiteSpeed, the output will look as follows, and we’re specifically looking for the highlighted line:

OS: Linux 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 Shell: /bin/bash PHP binary: /usr/local/lsws/lsphp80/bin/php PHP version: 8.0.26 php.ini used: /usr/local/lsws/lsphp80/etc/php/8.0/litespeed/php.ini MySQL binary: /usr/bin/mysql MySQL version: mysql Ver 8.0.30-22 for Linux on x86_64 (Percona Server (GPL), Release '22', Revision '7e301439b65') SQL modes: WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /root WP-CLI packages dir: /root/.wp-cli/packages/ WP-CLI cache dir: /root/.wp-cli/cache WP-CLI global config: WP-CLI project config: WP-CLI version: 2.7.1

The current CLI PHP version across GridPane servers is 8.0 as above. We can increase the memory_limit by editing this file with:

nano /usr/local/lsws/lsphp80/etc/php/8.0/litespeed/php.ini

Step 3. Adjust and Save

Use the down arrow key to scroll down to “Resource Limits“, and you’ll find the setting under:

; Maximum amount of memory a script may consume ; http://php.net/memory-limit memory_limit = XXX

Edit the limit value (numbers only), then save the file with CTRL+O followed by Enter. Exit nano with CTRL+X.

Step 4. Restart PHP

Finally, restart the appropriate PHP version with:

4.1 NGINX
4.2 OPENLITESPEED
touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt
systemctl restart lsws

Источник

Оцените статью