When your web server is low on memory

I’ll list some of the common things that could happen when your standard web server (Apache PHP MySQL) is low on memory (based on personal experience) :

  • PHP throws a “Fatal Error : Out of memory (allocated x) (tried to allocate y bytes)”, where x is a large number and y is usually a very small number. This one is easy to spot. (well, duh)
  • If you are running PHP as a CGI program ,  ”CGI process exited before printing response header” error  occasionally will be shown instead of the error above. This happens more often when I tried to access phpmyadmin. (probably because phpmyadmin used up way more resource than your average webpage)
  • Your script quits unexpectedly. This could happens sometimes and especially hard to track, since you’d usually thought that there was an error at your script (which is not the case). Most of the times, the script quits when it tries to execute a database query.
  • MySQL starts throwing “Error 12″, which means that the system refuses to give more memory to the storage engine (apparently because there was nothing left to give). In most case, this is the reason behind the quitting script above.
The points and arguments listed above might or might not be accurate, though, since I’m in no way an expert either, but I sure hope that someone somewhere could benefit from this. Have a good weekend.