0

I have a PHP application deployed on AWS Elastic Beanstack with ELB attached to it. When there is huge traffic I'm getting ELB 5XX/4XX errors. So from the below error, I found that the application has memory limit issues. I have increased the memory limit to -1. And sent huge traffic to different endpoints using Jmeter. I don't see any errors now. But I'm not sure whether the application using memory_limit -1 or not. any suggestions to test?

Error:

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32 bytes) in /var/app/current/XXXXX/XXXXX/AAAAAA.inc on line 222

Solution:

Added a file inside .ebexstentions to change the memory limit to -1

file: /etc/php.d/memorylimit.ini, mode: 000755 owner: root group: root content:

memory_limit=-1
0stone0
  • 34,288
  • 4
  • 39
  • 64
Pat
  • 1
  • 4
  • 1
    The active value should be present in `phpinfo()` or a call to `ini_get('memory_limit')` https://www.php.net/manual/en/function.ini-get.php – Michael Berkowski Feb 04 '20 at 21:03
  • @MichaelBerkowski Is there any way to get the active memory limit value using Shell commands ? – Pat Feb 04 '20 at 21:25

1 Answers1

0

The base limit is set in the .ini file as you have discovered. You can also override this setting in a particular script using ini_set('memory_limit', '128M'); and set the limit to a high number. I believe the max is based on the system RAM, and it's PER SCRIPT, but I seem to remember hitting a limit of 10GB when dealing with this before.

I would also check to see if there is a limit set in a .htaccess file

php_value memory_limit 256M

There are other stackoverflow threads like this one: PHP : settings memory_limits > 1024M does not work

EDIT: Looking back through my notes, we had an issue with Apache's mod_security too that was limiting upload size.

Revent
  • 2,091
  • 2
  • 18
  • 33
  • thanks for the response. Actually I'm looking for help to test the application for now. I want to know whether the application using the memory limit value as -1 or not. – Pat Feb 04 '20 at 21:26
  • From the command line (Linux), you can use this: `php --info | grep memory` or `php --info | grep memory_limit` to see what PHP thinks the setting is or as @michael-berkowski said add a file with phpinfo() and view it in the browser. – Revent Feb 04 '20 at 21:30
  • Seems like php --info | grep memory worked. But why it is listing old memory as well which is 128. sh-4.2$ php --info | grep memory /etc/php-5.6.d/memorylimit.ini, memory_limit => -1 => -1 Collecting memory statistics => No opcache.memory_consumption => 128 => 128 opcache.preferred_memory_model => no value => no value opcache.protect_memory => 0 => 0 – Pat Feb 04 '20 at 22:06
  • I know we are doing grep for memory but still what is for opcache.memory_consumption => 128 => 128 – Pat Feb 04 '20 at 22:08
  • That is how much memory is allocated for the opcache opcode cache, which stores in memory the script's compiled opcode's for faster execution. Separate thing from the memory limit ini setting. – Michael Berkowski Feb 05 '20 at 02:11