Categories


Archives


Recent Posts


Categories


PHP Meminfo and Memory Leaks

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

You can’t walk ten steps in this businesses without hearing Engineering is a set of tradeoffs. You rarely hear the other side of that: and sometimes we make the wrong tradeoffs which lead to living with garbage behavior for years.

PHP leaks memory like a sieve. By leak we mean during a long running PHP request the amount of memory will slowly increase over time because there’s some memory the garbage collector can’t free up. The usual response to this is a shrug, and mumbling some words about PHP’s process model taking care of this. i.e. PHP doesn’t have many long running requests so the leaks are an accepable tradeoff.

Until, of course, you have that long running import script, or your server’s getting a bunch of traffic that’s trashing your memory which in turn thrashes the CPU. Then you’re left with a the near impossible task of guessing which object instantiations are the ones PHP’s garbage collector can’t free up.

The new PHP Meminfo extesion isn’t a pancea, but it does look like a tool that can help you pinpoint which object references are the problem, and put you in a better position to deal with them. Also, burried in the repo is a link to some slides that have the most cogent explaination I’ve seen lately of why PHP has these sort of userland memory leaks. (The preseataion of these slides is probalby great, but I live in a second-and-a-half-world country and wasn’t taught French)

Copyright © Alan Storm 1975 – 2017 All Rights Reserved

Originally Posted: 17th November 2017