views:

125

answers:

1

Alright folks,

We've got Apache 2.2.11 running mod_php 5.2.9-2 on a Windows Server 2003 (Small Business Edition) box, and each request spikes somewhere around 4 to 8MB of RAM, followed by approximately 2 to 6MB of freeing. Basically, the amount Apache releases is always notably less (by megabytes) than the amount it allocates during the request, and after a few hours the httpd.exe process ends up consuming all available RAM and the server hangs.

This behaviour doesn't occur at all on our Windows XP development boxes with the same codebase and following configs:

  • XP/Apache 2.2.11/PHP5.2.9-2/MySQL 5.1.34
  • XP/Apache 2.0.x (various)/PHP5.2.7/MySQL 5.0.67

Simple PHP scripts on the production server (Win2k3) don't appear to leak e.g:

  • Basic PHP echo functions
  • Creating and referencing classes
  • Output buffering
  • PDO with and without persistent connections

When running our full app, however, things start to leak. The only things we can think of that would cause this are the use of objects, session details, global variables - but how can I find out what the leak is? And what's causing it? Without disrupting too much the only machine we can duplicate the issue on??

+1  A: 

PHP has it's own memory functions, and you can create __destroy magic functions to monitor objects. I personally would make a testing copy, make a few edits so you can monitor ram and see where it increases or decreases.

Personally I would have first assumed it was a caching issue, with the ram increasing, but if it renders the system unstable then it is clearly not so easy.

  echo "Before SomeStrangeObject == ".memory_get_usage()."<br>";
  $x = new SomeStrangeObject();
  echo "During SomeStrangeObject == ".memory_get_usage()."<br>";
  unset($x);
  echo "After SomeStrangeObject == ".memory_get_usage()."<br>";

And just look for obvious leeks. Sorry I can't be any more helpfull.

scragar
Hmm. We never do any explicit unset()ting or use __destroy. Our scripts themselves are using approx ~8MB after a call to memory_get_usage() right before the end of execution. We were assuming that Apache would be able to recover the memory from that particular request. I'm assuming it's not quite safe to assume this then?
Keith Humm