I can´t find an answer for this, probably I'm not searching with the right words.
When a PHP script fails (error in script, infinite loops, endless SQL calls, etc) the whole server goes "busy". It's like all the resources are taken and focus on trying to execute that script. By restarting apache/nginx the server goes back to normal.
How could this be avoided? Setting the timeout for the script won't solve it because if it's even 10 seconds timeout the server will be irresponsive for those 10 seconds to everybody.
Is there any way to avoid this happening? Yes, solving the script issues the problem will stop happening but I am sure there is a way to protect against this on the server side.
Just now an example comes to my mind. This script used to get the country code by calling a service in that website. For some reason the website would not serve to us randomly so the script would wait forever to receive the file contents.
$getcountry = file_get_contents('http://ip-api.com/php/'. getUserIP());