It is not clear why one day the script began to throw an error

PHP Fatal error : Allowed memory size of 4731174912 bytes exhausted (tried to allocate 256 bytes)

Moreover, the size 4731174912 in all cases the same and in different files (error). We tried to increase the limit in my.cnf , but it did not give any results. On the server, 16 GB, but for some reason rests on 4731174912.

Where can I increase the memory limit, or maybe the reason is something else?

usertype.php: enter image description here

database.php: enter image description here

  • And where is the script itself - Raz Galstyan
  • 2
    Why are you trying to increase the limit in my.cnf if the error occurs in PHP? - Sergey Gornostaev
  • one
    4.5GB per request? Hmm ... ... stackoverflow.com/a/598111/203622 for fix, memory_limit in php.ini for bury your head in the sand. - Shallow
  • Show the 2807 line of the usertype.php file and a dozen lines before and after this line - Anton Shchyrov
  • Yes, until we bury our heads, then we will understand. The script is just vital - it considers the salary) - Sergey

1 answer 1

  1. run phpinfo () instead of your code, look at the current memory_limit, see where your php.ini is
  2. edit it, change memory_limit to a larger value
  3. restart the web server if php is apache (or fpm)
  4. check in phpinfo that the changes are applied
  5. if the changes are not applied - either you edited the wrong config, or you didn’t execute the restart correctly, or it is controlled somewhere in your code (the value can be set in the script using the ini_set instruction ("memory_limit", "<memory>")

but all this is not a solution. 4 + GB per 1 hit - this is super-large, this should not be, the code needs to be optimized.

  • That's exactly what phpinfo shows 256M. Yes, this is an abnormal situation, you need to understand. Strange, all of a sudden it started from the 1st ... And looking at the commits - the previous one is 26.04, the next is 5.05. Ie, nothing has changed ... - Sergey
  • the fact that the code has begun to “eat” the memory does not yet indicate that this happened because of changes in it. it is quite possible that the code worked back on the old input data, but nevertheless contained an error that occurred when the data was changed - Artem Malahov
  • I want to see a solution to the problem in the form of an increase in memory, at least. How much should I put? 10GB? - Sergey
  • The algorithm above, look for configs, edit, restart the server. Well, you need to check that the limit is not set somewhere in the application code via ini_set - Artem Malahov
  • So I found the config, in php.ini the value of memory_limit increased from 128M to 256M. The result has not changed. The question is - am I doing everything right? Is it worth increasing further? - Sergey