My Drupal-oriented shared webhost recently updated PHP and APC and turned on reporting APC warnings. Now my watchdog log has many, many entries of the form Warning: include() [function.include]: Unable to allocate memory for pool, indicating that sometimes the cache is overflowing.

I know what these warnings mean: that's not my question. The APC cache is 96MB, which is big enough most of the time. But I have 127 enabled modules and certain page loads or doing admin work will overflow the cache. This doesn't occur on every page load by any means, but the warnings are filling up the log, making it hard to find more interesting entries, and causing the log to wrap more often than I'd like. I'm trying to cut down my needed modules but nearly all are there for good reasons.

I cannot change most of the APC settings (I might wish to use apc.filters, for instance).

Is there any module or other method that you know of that will filter messages before they get put in the log? I could make the log bigger, but I still have the problem of finding the wheat in the chaff of warnings.

  • As a side note, I know the dblog can be useful/necessary at times but it's preferable to use syslog to log to the file system and turn off dblog. This saves on lots of unnecessary database hits. It's also easy to search for things in the file logs and repetitive warnings aren't so bothersome. – rooby Oct 23 '14 at 12:18

You can create a module to use the hook_watchdog function. This hook would kick in when there is an error so you can check the type of error decide not to write it to the table. But the variable seems to be passed not as a reference and hence I dont think you would be able to change the variable it self.

The logs are written to the table by the dblog module. using the hook implementation of the dblog module. Just make sure that your function gets called after this so that the entry is already in the db. this should be the case already if not you can set the priority in the systems table to make this effect.

Now within your hook function you can decide to delete the entry that is just written.

function dblog_watchdog(array $log_entry) {
  Database::getConnection('default', 'default')->insert('watchdog')
    'uid' => $log_entry['uid'], 
    'type' => substr($log_entry['type'], 0, 64), 
    'message' => $log_entry['message'], 
    'variables' => serialize($log_entry['variables']), 
    'severity' => $log_entry['severity'], 
    'link' => substr($log_entry['link'], 0, 255), 
    'location' => $log_entry['request_uri'], 
    'referer' => $log_entry['referer'], 
    'hostname' => substr($log_entry['ip'], 0, 128), 
    'timestamp' => $log_entry['timestamp'],

Another option would to create a hook_cron in your module and delete the wantchdog entries you dont want during the cron run.

  • Thanks - I did not know about this hook. This gives me the idea of using the hook to collapse multiple identical or similar entries into one and keeping a count (in the text, say). Then I don't lose the info but but the log isn't flooded. – – Dan Halbert Jan 27 '13 at 15:49
  • good to know it helps :-) – Mohammed Shameem Jan 27 '13 at 15:50

Better to fix the APC error than suppress the error msg..

Note, more recent versions of PHP require the unit suffix on apc.shm_size

You might see an server log error PHP Warning: PHP Startup: apc.shm_size now uses M/G suffixes, please update your ini files

  • incorrect: apc.shm_size 256
  • correct: apc.shm_size 256M

There's also an issue queue for the Unable to allocate memory for pool error, with a few suggested solutions here:


  • Thanks for the suggestions. I don't think there are actually any real errors. The cache is simply filling up and getting so fragmented I see the warnings. I did see the php.net bug you mention, but the APC settings are OK (and I can't change most of them anyway due to the server setup). This is of interest: stackoverflow.com/questions/3723316/…. I wish APC was able to allocate in multiple fixed-size chunks: then the whole fragmentation issue would not arise and it could just do LRU quietly. – Dan Halbert Jan 27 '13 at 14:54

Change you apc.ini settings like below


it works

Refer apc.configuration.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.