PHPucEU2011SaturdaySessionA3

From PHPucEU

Jump to: navigation, search

Memory Management, Garbage Collection, destruct(), debugging memory

A discussion group/panel led by James Baster and Derick Rethans

__destruct can be used to break circular references etc but can end up really really nasty

5.3 has Circular reference detection which when it hits a certain point will loop over and free the resources. Read up at:

- http://derickrethans.nl/collecting-garbage-phps-take-on-variables.html
- http://derickrethans.nl/collecting-garbage-cleaning-up.html
- http://derickrethans.nl/collecting-garbage-performance-considerations.html

Ramping up the memory is always going to increase the memory usage to the that amount and not always the lower resource usage

Phergie, an IRC bot is a definition of a long running process.

- http://phergie.org/

PHP Variables create ZVal in larger blocks which will be cached. There are limits to the usage to that.

Mentioning of SPL Fixed array

- http://php.net/splfixedarray

unsetting variables in a loop will help but it's not the complete answer

variable names and array keys (string) are put in symbol tables which will keep a hash value of the string, the longer the variable name the large the amount of storage and the longer it takes to generate the hash. If you have this level of issues, you should probably be looking at writing a php extension.

variable variables and eval are evil.

Tools for memory use checking.

XHPROF - tutorial by Lorenzo Alberton:

- http://www.alberton.info/profiling_with_xhprof_the_path_to_scalability.html
- http://mirror.facebook.net/facebook/xhprof/doc.html

Hidden XDebug bits Function tracing:

- http://derickrethans.nl/xdebug-and-tracing-memory-usage.html
- http://xdebug.org/docs/execution_trace

Garbage collection still has some issues that are going to get fixed.

Readfile usage

php internals are quite smart in not duplicating data if it don't have to. use references for actual usage reasons and do not use php references for memory management. You will end up using more memory as it will copy/duplicate the data internally

Visit Dericks Blog for more information and lovely diagrams:

- http://derickrethans.nl/php-references-article.html
- http://derickrethans.nl/circular-references.html

memory management is not fun, especially when you have to manage it yourself.

do Opcode caches have an effect on memory usage, yes they do as they can share memory between processes, which can reduce memory usage. APC is good at this

Xdebug is more for debugging and will have more overhead than xhprof as xhprof really only for profiling. Xdebug more dev/staging xhprof more end of code.

- http://mirror.facebook.net/facebook/xhprof/doc.html
- http://xdebug.org

Derick spoke some more on a possibly opcoming feature in Xdebug where you can tell it to be in a specific mode: profiler, debugger, etc.

Personal tools