Re: Memory profiler for PHP?

From: Date: Tue, 29 May 2007 20:40:31 +0000
Subject: Re: Memory profiler for PHP?
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-7887@lists.php.net to get a copy of this message
On Tuesday 29 May 2007, Andre Colomb wrote: > I guess most people use PHP for writing dynamic web content, so the > execution times of a script are usually short. But how about us poor > PHP-Gtk users who have applications that might run a single script for > hours and hours with lots of scope changes and setting / unsetting > variables. Don't design your daemons this way if you can help it. I tend to write my daemon-style stuff like this: 1) A "taskmaster" which launches a 2) time-limited "grunt-worker". The taskmaster does nothing but check if itself and any grunt workers exist, and if so, terminates. 3) Otherwise, it goes into a loop and launches the grunt-worker process. 4) The grunt-worker process does a certain amount of work, and then quits. 5) Then, the taskmaster relaunches, etc. 6) Sometimes, if there's a hiccup in the grunt client, it'll get "hung up". A good example of this is in socket connections. So, sometimes I'll have a directory of files that get touched by the process periodically. If the process hangs for a period of time, the touch file will go stale and the taskmaster will know to issue a kill on the grunt-worker process and restart it. I can run major amounts of processing, at times with hundreds (or more) of grunt-worker processes running alongside each other with very good stability this way, even when there may be known problems and memory leaks with the grunt-worker process code. > However, when running my application, I can observe a constantly > growing memory footprint in the Windows Task Manager. Sometimes the > value drops down significantly (e.g. when clear()ing a GtkTreeModel), > but overall it tends to get bigger and bigger. Look for the leaks. If you look hard enough, you'll find 'em. Or, redesign your architecture so the memory gets cycled out periodically. As stated in another response, PHP reuses allocated memory, so an endlessly growing memory usage indicates stuff isn't being marked as "empty", and so therefore there is a memory leak. > Now, where could this effect come from? Is there any kind of memory > profiler for PHP (like electric-fence or dmalloc for C)? None that I know of. But it'd sure be nice! -Ben -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.

« previous php.gtk.general (#7887) next »