Found below by checking the error log:
PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes)
so then i have tried it to reproduce on my local setup. So what i did is changed the memory_limit
to 10 MB and tried to call one of API manually. In that case server return 500 which is correct (i.e. display above error with 500 HTTP Status).
But now if i set it to 1MB then it returns 200 HTTP status (without processing any thing, i have simple message on first line.). So what is the reason behind it and how to solve it?
In short if server returns 500 for 10 MB limit then it should also return 500 for 1MB correct?
Is it possible that some how apache return default HTTP Status if it can’t process the request? If yes how can we know the default HTTP status and how one can change that?
PHP Version: 7.0.33
Apache Version: 2.4.39
With Memory limit 1 MB
With 10 MB limit
update
I didn’t posted the code because i thought it was irrelevant because above issue occur when there is too much traffic on server and it happen for any api which i have. We have one voucher selling feature and when it start we receive too many request and during that time period we face above memory error other time we don’t face it. So my thought was because there might be no memory to process the request and hence server return default 200. To achieve that i have set memory limit too low in my local setup.
So question is how force the server to return 500 if there is no memory to process the request.
2
Answers
It’s likely that PHP responded with a 200 before PHP issued an error about memory use when it was moderately high. The HTTP status goes out over the wire before any of the body.
If you set it low enough, your script probably doesn’t get far enough to issue the status and headers.
I had a similar problem with apache.
Have you tried to launch this api on a clean apache if it keeps not working?
Else you checked the rules about memory with the proper configuration?