I am working in magento 2.2.2 and when I save product It will display this error.

Fatal error: Allowed memory size of 792723456 bytes exhausted (tried to allocate 184320 bytes) in /var/www/html/Demo/vendor/magento/framework/Profiler.php on line 153

Php version : 7.0

Magento : 2.2.2

I also changes apply in memory_limit = 16G in php.ini file and restart apache server. still, this issue not fixed.

namespace Abc\Xyz\Observer;

use Magento\Framework\Event\ObserverInterface;
use \Magento\Store\Model\StoreManagerInterface;

class ProductSaveAfter implements ObserverInterface
    protected $_objectManager;
    protected $messageManager;
    protected $_productmFactory;
    protected $_productdFactory;
    protected $_productsFactory;
    protected $_eavConfig;
    protected $sStore;
    protected $scopeConfig;
    protected $_helper;
    protected $storeManager;

    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Magento\Framework\App\RequestInterface $request,
        \Magento\Eav\Model\Config $eavConfig,
        \Abc\Xyz\Helper\Data $helper,
        StoreManagerInterface $storeManager,
        \Abc\Xyz\Model\productmFactory $productmFactory,
        \Abc\Xyz\Model\ProductdFactory $ProductdFactory,
        \Abc\Xyz\Model\productsFactory $productsFactory,
        \Abc\Xyz\Model\sStoreFactory $sStoreFactory,
        \Magento\Framework\Message\ManagerInterface $messageManager
    ) {
        $this->_objectManager = $objectManager;
        $this->_request = $request;
        $this->_helper = $helper;
        $this->scopeConfig = $scopeConfig;
        $this->_eavConfig = $eavConfig;
        $this->_productmFactory = $productmFactory;
        $this->_productdFactory = $ProductdFactory;
        $this->_productsFactory = $productsFactory;
        $this->sStore = $sStoreFactory;
        $this->storeManager = $storeManager;
        $this->messageManager = $messageManager;
    public function execute(\Magento\Framework\Event\Observer $observer)
        $product = $observer->getEvent()->getProduct();
        $id = $product->getId();
        $data = $this->_request->getParams();
        $currentWebsite = $this->storeManager->getStore()->getWebsiteId();
            if ($id) {
                $YG14 = $this->_request->getParam('YG14');
                $YG14_size = $this->_request->getParam('YG14_size');

                $mI = $this->_productmFactory->create()->getCollection();
                $mI->addFieldToFilter('product_id', $id);
                /** Delete all records*/
                if ($YG14 != "") {
                    if (!empty($mI)) {
                        foreach ($mI as $mtl) {
                            $mI = $this->_productmFactory->create()->load($mtl->getId());

                if ($YG14 != "") {
                    $mISave = $this->_productmFactory->create();
                $dD = $this->_request->getParam('d');
                if ($dD) {
                    $dInfoDelete = $this->_productdFactory->create()->getCollection()->addFieldToFilter('product_id', $id);
                    foreach ($dInfoDelete as $key => $dia) {
                        $dInfo = $this->_productdFactory->create()->load($dia->getId());
                    foreach ($dD as $d) {
                        $dS = $this->_productdFactory->create();
                        if (array_key_exists('d_s', $d)) {
                        if (array_key_exists('d_w', $d)) {
                        if (array_key_exists('d_q', $d)) {
                        if (array_key_exists('d_s_t', $d)) {
                } else {
                    $deld = $this->_request->getParam('deld');
                    if ($deld != "") {
                        $delD = explode(",", $deld);
                        foreach ($delD as $delDIds) {
                            $dD = $this->_productdFactory->create()->load($delDIds);
                $sD = $this->_request->getParam('st');
                if ($sD) {
                    foreach ($sD as $sts) {
                        $ssSave = $this->_productsFactory->create();
                        if (isset($sts['st_ids'])) {
                        if (array_key_exists('st_c', $sts)) {
                        if (array_key_exists('st_sett', $sts)) {
                        if (array_key_exists('st_s', $sts)) {
                        if (array_key_exists('st_w', $sts)) {
                        if (array_key_exists('st_q', $sts)) {
                        $sStore = $this->sStore->create();
                        $sStoreExists = $sStore->getCollection()->addFieldToFilter('st_id', $ssSave->getId())->addFieldToFilter('website_id', $currentWebsite);
                        if (!empty($sStoreExists->getData())) {
                            foreach ($sStoreExists as $value) {
                        } else {
                            if (array_key_exists('price', $sts)) {
                    $delSt = $this->_request->getParam('delSt');
                    if ($delSt != "") {
                        $delS = explode(",", $delSt);
                        foreach ($delS as $delSIds) {
                            $dDelete = $this->_productsFactory->create()->load($delSIds);
                } else {
                    $delSt = $this->_request->getParam('delSt');
                    if ($delSt != "") {
                        $delS = explode(",", $delSt);
                        foreach ($delS as $delSIds) {
                            $dDelete = $this->_productsFactory->create()->load($delSIds);

                $prices = $this->_helper->defaultPriceCalculate($id, $product, $currentWebsite);
                if ($prices['discountedPrice'] != 0) {

        } catch (\Magento\Framework\Exception\LocalizedException $e) {
        } catch (\RuntimeException $e) {
        } catch (\Exception $e) {
            $this->messageManager->addException($e, __('Something went wrong while saving the post.'));

How to solve it ?

Please help me.

  • Show your code which you are used for save product. Jan 18, 2018 at 12:10
  • You can set memory size to -1, so it will use the required memory size, setting is ini_set('memory_limit', -1); Jan 18, 2018 at 12:26
  • Check it @SureshChikani Jan 18, 2018 at 12:36
  • At which place I put memory size -1 ? Jan 18, 2018 at 12:36
  • You can put it in index.php file at your root of magento. Jan 18, 2018 at 12:37

6 Answers 6


Try following commands:

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento setup:di:compile
php bin/magento cache:flush
php bin/magento cache:clean

//To run command forcefully
php -f bin/magento

//To run command with memory limit 4G
php -d memory_limit=4G bin/magento

//To run command with max memory limit
php -d memory_limit=-1 bin/magento

If you are still facing issue then try following settings:

  1. [Magento2-root-folder]/index.php



Check current memory_limit value using CLI:

1. php -r "echo ini_get('memory_limit').PHP_EOL;"

2. php -i | grep memory

If the issue are still persist then increase the memory limit (e.g., up to 2048M) in the following places:

  1. [Magento2-root-folder]/.user.ini
memory_limit = 768M
  1. [Magento2-root-folder]/.htaccess (2 places)
php_value memory_limit 768M
  1. [Magento2-root-folder]/pub/.user.ini
memory_limit = 768M
  1. [Magento2-root-folder]/pub/.htaccess (2 places)
php_value memory_limit 768M

Issue should be resolved by now, if it is still there then disable your custom module and check again.

  • 1
    super. thank you. edit .user.ini helped me.
    – James M
    Apr 27, 2018 at 10:37
  • 1
    Thank you very useful for me, I have added this and issue resolved Mar 20, 2019 at 6:16
  • 1
    Explanation is great. Keep it up this approach
    – Jarnail S
    Jun 29, 2019 at 7:35
  • 1
    First lit of commands worked for me. Thx!
    – Alex B
    Nov 17, 2020 at 18:19
  • 1
    "php -d memory_limit=-1 bin/magento setup:di:compile" worked
    – Dipu R
    Jul 21, 2021 at 9:01

A quick solution is

php -dmemory_limit=6G bin/magento setup:static-content:deploy

Try this, Its worked for me.


792723456 bytes mean 756 MB. This is the value that Magento suggests and is the default on their sample configs(nginx in particular).

Do try everything that @Pratik Oza suggested and let me point to another place. Are you using php-fpm or a similar CGI? If so then please do check for memory limits there too.

In my case i am using nginx + php-fpm and i set the memory_limit per project using the

php_value[memory_limit] = [N]MB

Also if you are using a CGI then try this. First stop your webserver then restart you CGI and then start your webserver again.

The is a random problem i faced once that had me doing the above.If i did not then it was like nginx set it's own values to anything passed to php-fpm without caring for the values set on php.ini or fpm.conf.

EDIT: I see the problem was solved by editing the .user.ini. That means that it was actually nginx that passed another value and could also be the case i described. Just pointing this one out. Also to anyone reading the other answers please do not use set_init('memory_limit',-1) EVER.

I've seen a developer of mine using this to test out a mysql query optimization and the script reached a 35gigs ram which kept increasing until i killed it after 10mins. Just set the value to a decent threshold until you get to the running point and leave it there or fix the values or the perspectives user.ini/fpm.conf/fascgi parameter.

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:flush

php bin/magento cache:clean

It definitely be work.


This tripped me up when installing from archive instead of composer for magento 2.3. In my case, the settings I was changing was in the wrong place.

Was updating:

vi /etc/php/7.2/cli/php.ini

needed to update:

vi /etc/php/7.2/apache2/php.ini

This is for both errors like:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted


PHP Fatal error:  Maximum execution time of 30 seconds exceeded in....

Also make sure to enable rewrite: a2enmod rewrite if having issues with pages.


none of the above options not worked for me.

My server is nginx. It memory limit defined in /etc/nginx/magento.conf

open the file and search

fastcgi_param  PHP_VALUE "memory_limit=

inside the below block

location ~ (index|get|static|report|404|503|info|cleanopcache)\.php$ {


after found that line, the memory limit has to set as 6144M

fastcgi_param PHP_VALUE "memory_limit=6144M \n max_execution_time=600";

after that, it works fine.

you able to find how much memory limit set in your Magento projects via debug log.

make log with ini_get('memory_limit');

hope this helps you all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.