1

I'm running my custom script on Magento 2. It gives below error.

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93
PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/Session/SessionManager.php on line 139
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/magento/vendor/magento/framework/Session/SessionManager.php on line 139

Do I need to set

ini_set('memory_limit', '6G');

?

On the start of script or need to change in php.ini

3
  • You can change in start of your script. Commented May 26, 2017 at 6:02
  • Hi @RakeshJesadiya i need to put ini_set in start of my script right?
    – Jackson
    Commented May 26, 2017 at 6:03
  • Yes you have to keep it start of script Commented May 26, 2017 at 6:17

3 Answers 3

2

Change the setting in php.ini and restart server. There is no need to change in code or put in start of file because best solution is to do in php.ini.

You can also try in .htaccess.

Comment if face issue again. I will help you to sort out.

0

Add it in app/bootstrap.php. bootstrap.php is included in cron, frontend, api.

-1

From cli you can do: php -d memory_limit=4G .... From web request you should just write better code. There is no need for a webserver to use more than 8Mb of memory.

2
  • 8Mb, seriously :) Commented Oct 4, 2017 at 15:26
  • Ofcourse, if your page is 200Kb than you only have a overhead of 3200%. That would normaly be enough for a Php Script Kiddy. But yeah, your right. Not for all of them 3200% is enough overhead. Commented Oct 9, 2017 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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