next up previous contents
Next: Can I have multiple Up: Frequently Asked Questions Previous: Why not use macros   Contents

Why do I keep running out of memory?

PHP rarely runs beyond its memory limit in apache because the instance only lives for the time it takes to serve one page and then that thread dies and the memory is freed. The embedded environment, however, sticks around and hence requires vigilance around declaring variables in global scope and failing to clean them up with unset. Additionally, it may help to increase the allowed operating memory by using the ini_set function before loading any PHP scripts, for example: ini_set('memory_limit', '100M');

There are also a few known leaks in the PHP core, using the builtin PHP function memory_get_usage() in conjunction with the memory_limit ini setting will enable any client of PHPEmbed to predict a memory problem before it affects program operation and handle it as appropriate, for example by destroying the PHP object and recreating it.



Andrew Bosworth 2008-03-24