Reputation: 395
I run a site that is slowly but surely draining all of the available memory in Apache. Not sure how long it's been going on for - the server is set up to auto-reboot if the memory limit is reached, and the sysadmin has set up Apache so that the threads are recycled (I forget the exact details here... basically it stops the server dying when the memory is all used up).
Some tech specs:
What I've managed to find out:
Doctrine may be to blame, but I'm not 100% sure. Doctrine is run via the _initDoctrine method in the bootstrap. Some of the bits I'm using are as follows:
$config = new Configuration;
$arrayCache = new ArrayCache;
$cache = new Doctrine\Common\Cache\MemcacheCache;
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$cache->setMemcache($memcache);
$cache->setNamespace("PDC_");
\Zend_Registry::set("pdc_memcache", $cache);
//$query->setResultCacheDriver($cache);
$config->setMetadataCacheImpl($arrayCache);
$config->setQueryCacheImpl($arrayCache);
// Metadata Driver
$driverImpl = $config->newDefaultAnnotationDriver(array(APPLICATION_PATH.'/Db/Entities'));
$config->setMetadataDriverImpl($driverImpl);
// Proxy configuration
$config->setProxyDir(APPLICATION_PATH.'/Db/Proxies');
$config->setProxyNamespace('Dpp\Proxies');
//if (APPLICATION_ENV == "development") {
$config->setAutoGenerateProxyClasses(true);
This is not the complete code - I've tried to include the parts that I thought might be useful.
Any ideas would be much appreciated... Thanks.
Upvotes: 1
Views: 1500
Reputation: 35169
Apache with mod_php will obey the 'MaxRequestsPerChild' directive if required. This can restart the Apache/mod_php process after (say) 10,000 requests to clean up any memory leaks. After that is in place, you can start some investigations as to exactly where the issue is happening, and so remove the problem. Something as simple as using memory_get_usage() can be useful for that, or using Xdebug/XHprof for more widespread memory profiling.
Upvotes: 1