Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) Laravel

寵の児 提交于 2021-02-18 22:12:45

问题


I have a problem with Laravel . after restart my system, My project will not run !!!

I run with php artisan serv , but I have below messages in console :

[Tue Jul  3 14:31:35 2018] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /laravel-projects/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122
[Tue Jul  3 14:31:35 2018] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /laravel-projects/blog/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 46
[Tue Jul  3 14:31:38 2018] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /laravel-projects/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122
[Tue Jul  3 14:31:39 2018] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /laravel-projects/blog/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 46
[Tue Jul  3 14:31:39 2018] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /laravel-projects/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122

Before the system was restored, the project was well implemented !!


回答1:


This means you need to also update your php.ini memory_limit directive.

Try put in your php.ini :

memory_limit=1024M and restart apache :

sudo systemctl restart httpd.service




回答2:


Change in php.ini which is there inside apache2 folder

memory_limit=1024M

restart apache2

you can even check which php ini config is using by:

php -i | grep "php.ini"



回答3:


This problem occurs when an application uses more memory than PHP allows. thanks to PHP's relatively conservative default memory settings. you can fix this issue by change memory_limit size in your php.ini

memory_limit= Replace your size(1024M /2048M/etc) change and save it, then restart the services.

  • In Windows, you can find "C:\wamp64\bin\php\php_version\php.ini" then restart your service.

  • In Ubuntu, you can find "/etc/php/php_version/apache2/php.ini" then run sudo systemctl restart apache2 for restart apache.

You can simply increase the memory limit programmatically early on in your code, before your process runs out of memory. If you do it this way, you can give PHP extra memory only when that piece of code gets called rather than increasing the memory limit for all PHP processes.

ini_set('memory_limit', '1024M');



回答4:


php -d memory_limit=1024M artisan serv

If you don't want to change global php.ini settings or you dont have access to change it. Then this workaround will work to get things done.

Make sure you are using correct php version, as sometimes php-cli may have set to some other version, that might cause some other issues.



来源:https://stackoverflow.com/questions/51152078/allowed-memory-size-of-134217728-bytes-exhausted-tried-to-allocate-20480-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!