Linux – How to find out what sites are using too much RAM on the linux web hosting box

linuxmemoryweb-server

Situation

I have root access to a virtual private server (on Dreamhost) where I host my web sites. I am limited by RAM (currently 500 MB) so if one site (script of this site) demands too much RAM my whole VPS is shut down and restarted, taking all other sites down with it!

My average usage is about 100 MB, so nowhere near the limit, yet somehow some script still does this: asks for too much RAM and then Dreamhost's watchdog kills my VPS. It all happens in milliseconds (so they say) and I can't easily find out what's happening.

Question

How can I find out what script is causing this? Dreamhost hasn't been helpful with this and I'm not exactly the best linux hacker :).

Some more details

All my sites are hosted on Apache and they are all in PHP.

Best Answer

Drop the PHP memory limit to a lower value (memory_limit config var in php.ini); the script that's consuming all the memory will error out and that'll identify the problem. If the problem still happens without visible error, keep dropping the memory limit. If everything starts erroring out, you dropped it too far. If you can't find a happy medium between "everything dies" and "nothing dies", consider the possibility that it's not actually a PHP script hogging all your memory, and start looking at other possibilities (cron jobs, background processing jobs, that sort of thing).

Related Topic