Title: Memory allocation errors in error log
Last modified: February 22, 2018

---

# Memory allocation errors in error log

 *  [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/)
 * Hello,
    I am seeing these errors in the error log almost daily: … mod_fcgid: 
   stderr: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
   to allocate 1048577 bytes) in /var/www/vhosts/exampe.com/httpdocs/blog/wp-content/
   plugins/wordfence/lib/wordfenceScanner.php on line 307
 * How much memory does this plugin really need? I already increased allowed memory
   to 256M (as you can see above) and it still doesn’t seem to be enough… any thoughts?

Viewing 13 replies - 1 through 13 (of 13 total)

 *  [wfyann](https://wordpress.org/support/users/wfyann/)
 * (@wfyann)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10001211)
 * Hi [@mishash](https://wordpress.org/support/users/mishash/),
 * It appears that in your case 256M is indeed not enough; it depends on your site,
   resources, and plugins and themes.
 * Please see [this article](https://www.wordfence.com/help/scan/troubleshooting/#php-fatal-error-allowed-memory-size-exhausted)
   from our documentation which addresses this question.
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10029414)
 * Thanks [@wfyann](https://wordpress.org/support/users/wfyann/). I read the article,
   but it seems to be a bit extreme for a security plugin to use over 256M, even
   for big sites. Based on my 20+ years of software experience, when you write a
   code, you should expect this code to operate within reasonable resources rather
   than expect unlimited resources. And 256M is more than reasonable… 🙁
 *  [wfyann](https://wordpress.org/support/users/wfyann/)
 * (@wfyann)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10029483)
 * Hi [@mishash](https://wordpress.org/support/users/mishash/),
 * As explained in the article the PHP _memory\_limit_ applies to all PHP processes
   running at given time (not only Wordfence related PHP processes).
 * For example, if you have 10 plugins and combined they consume more memory than
   you have allocated, you’re going to encounter this error.
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10029551)
 * Thank you [@wfyann](https://wordpress.org/support/users/wfyann/), now I understand.
   I didn’t realize the limit applies to all PHP processes. Will increase the limit
   to 512M, hopefully the errors will go away.
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10035761)
 * [@wfyann](https://wordpress.org/support/users/wfyann/), I increased memory limit
   to 512M, restarted Apache service and run manual scan. 5 min into the scan I 
   got the following error:
    [MAR 03 18:27:32] Fatal error: Allowed memory size 
   of **536870912** bytes exhausted (tried to allocate 1048577 bytes) in /var/www/
   vhosts/exampe.com/httpdocs/blog/wp-content/plugins/wordfence/lib/wordfenceScanner.
   php on line 303
 * **There is certainly a serious problem with memory allocation in Wordfence, as
   the only errors in the log (related to PHP memory) are from Wordfence plugin 
   and, considering that I just doubled the allowed memory to 512M, it is obvious
   that Wordfence used up extra $256M on it’s own in 5 min of operation.**
    -  This reply was modified 8 years, 3 months ago by [mishash](https://wordpress.org/support/users/mishash/).
    -  This reply was modified 8 years, 3 months ago by [mishash](https://wordpress.org/support/users/mishash/).
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10035819)
 * Well, I checked the “Use low resource scanning” checkbox and… the result is exactly
   the same, it runs out of memory at exactly the same point. In fact, the only 
   difference in the log between records for the “low resources” block and regular
   resources bock is one line “Using low resource scanning”, so it looks like this“
   low resources” checkbox makes no difference at all. I’ve been using Wordfence
   for over 3 years and never had such problems in previous versions 🙁
 * Here is the log with 2 scans (with and without low resources setting): [https://justpaste.it/1ht0n](https://justpaste.it/1ht0n)
 *  [wfyann](https://wordpress.org/support/users/wfyann/)
 * (@wfyann)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10037604)
 * Hi [@mishash](https://wordpress.org/support/users/mishash/),
 * What value have you specified for the “[How much memory should Wordfence request when scanning](https://www.wordfence.com/help/scan/options/#max-memory)”
   parameter?
 * You can check that on the “_All Options_” page in the “_Scan Options –> Performance
   Options_” section.
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10038144)
 * Hi [@wfyann](https://wordpress.org/support/users/wfyann/)
    I tried 3 values: 
   empty (i.e. default), 128Mb, 256Mb. End result is the same: out of memory error.
   FYI, the site has 118 posts and 43 pages. It is running Weaver Xtreme theme and
   has 14 plugins installed – see [this image](https://www.dropbox.com/s/p1nq4mp4gv8yyu6/plugins.jpg?dl=0)
   for plugin list/impact. As I already mentioned, I am running Wordfence since 
   2014 and had no issues with scanning until the last version. The site is running
   on VPS with dedicated CPU core and 2Gb of RAM. According to monitoring software,
   typical allocated memory rarely exceeds 1Gb, so there should be plenty of memory
   available.
    -  This reply was modified 8 years, 3 months ago by [mishash](https://wordpress.org/support/users/mishash/).
    -  This reply was modified 8 years, 3 months ago by [mishash](https://wordpress.org/support/users/mishash/).
 *  [wfyann](https://wordpress.org/support/users/wfyann/)
 * (@wfyann)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10159051)
 * Hi [@mishash](https://wordpress.org/support/users/mishash/),
 * Sorry about the delayed update.
 * Could you please run scans with “[debugging mode](https://www.wordfence.com/help/tools/diagnostics/#debug-mode)”
   enabled and check if it’s always failing right after scanning one specific file.
 * It looks like the issue occurs when the scanner is reading a file in chunks and
   it’s failing trying to calculate the size of the file.
 * Can you confirm that it’s always happening with the same file? If so, could you
   try excluding that file from scan?
 *  [wfyann](https://wordpress.org/support/users/wfyann/)
 * (@wfyann)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10161277)
 * Hi [@mishash](https://wordpress.org/support/users/mishash/),
 * Could you also please confirm if you have either of [these plugins](https://www.wordfence.com/help/scan/troubleshooting/#plugin-conflicts)
   installed on your site?
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10161677)
 * Hi [@wfyann](https://wordpress.org/support/users/wfyann/), I don’t use Query 
   Monitor and W3 Total Cache plugins.
 * I enabled Debug mode in Diagnostics and tried 3 scans. In these 3 scans the “
   out of memory” error happened when scanning totally different files. When looking
   at debug output in log files I can clearly see that allocated memory slowly grows
   to 510M+ and it never gets released. Please see below the logs from 3 scans prior
   to the error:
 * Scan 1
    • [Apr 09 13:35:52] Scanning contents: wp-content/plugins/wp-rocket/vendor/
   composer/installers/src/Composer/Installers/KodiCMSInstaller.php (Size: 219 B
   Mem: 509.5 MB) • [Apr 09 13:35:52] Scanning contents: wp-content/plugins/wp-rocket/
   vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php (Size:
   167 B Mem: 510.75 MB) • [Apr 09 13:35:52] Scanning contents: wp-content/plugins/
   wp-rocket/vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.
   php (Size: 726 B Mem: 511.75 MB) • [Apr 09 13:35:52] Fatal error: Allowed memory
   size of 536870912 bytes exhausted (tried to allocate 1048577 bytes) in /var/www/
   vhosts/example.com/httpdocs/blog/wp-content/plugins/wordfence/lib/wordfenceScanner.
   php on line 303
 * Scan 2
    • [Apr 09 13:56:18] Scanning contents: wp-content/plugins/wp-rocket/vendor/
   composer/installers/tests/bootstrap.php (Size: 111 B Mem: 507.25 MB) • [Apr 09
   13:56:18] Scanning contents: wp-content/plugins/wp-rocket/vendor/jamesryanbell/
   cloudflare/composer.json (Size: 498 B Mem: 508.25 MB) • [Apr 09 13:56:18] Scanning
   contents: wp-content/plugins/wp-rocket/vendor/jamesryanbell/cloudflare/composer.
   lock (Size: 68.05 KB Mem: 509.5 MB) • [Apr 09 13:56:18] Fatal error: Allowed 
   memory size of 536870912 bytes exhausted (tried to allocate 283605 bytes) in /
   var/www/vhosts/example.com/httpdocs/blog/wp-includes/wp-db.php on line 3122
 * Scan 3
    • [Apr 09 14:13:35] Scanning contents: wp-content/uploads/123rf-52128799_s-
   450×300.jpg (Size: 21.33 KB Mem: 509 MB) • [Apr 09 14:13:35] Scanning contents:
   wp-content/uploads/123rf-52128799_s.jpg (Size: 41.89 KB Mem: 510.25 MB) • [Apr
   09 14:13:35] Scanning contents: wp-content/uploads/123rf-52590276_s-150×150.jpg(
   Size: 4.35 KB Mem: 511.5 MB) • [Apr 09 14:13:35] Fatal error: Allowed memory 
   size of 536870912 bytes exhausted (tried to allocate 1048577 bytes) in /var/www/
   vhosts/example.com/httpdocs/blog/wp-content/plugins/wordfence/lib/wordfenceScanner.
   php on line 303
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10161725)
 * Actually, it’s not entirely true that memory never got released. It got released
   just before starting scanning plugins (wp-content/plugins/) and uploads (wp-content/
   uploads/). I assume that if you release the memory after scanning plugins block
   and before starting uploads everything will work fine. Just a guess…
 *  Thread Starter [mishash](https://wordpress.org/support/users/mishash/)
 * (@mishash)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10161792)
 * Hi [@wfyann](https://wordpress.org/support/users/wfyann/), I excluded all folders/
   files for the WP Rocket caching plugin and was able to complete the scan without
   errors. The maximum amount of allocated memory went to 410M. Not sure whether
   you want to add WP Rocket to the list of “conflicting” plugins as it doesn’t 
   really conflicts, it just caches a lot of files locally. Proper solution would
   be to release the memory as it approaches the limit.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Memory allocation errors in error log’ is closed to new replies.

 * ![](https://ps.w.org/wordfence/assets/icon.svg?rev=2070865)
 * [Wordfence Security - Firewall, Malware Scan, and Login Security](https://wordpress.org/plugins/wordfence/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordfence/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordfence/)
 * [Active Topics](https://wordpress.org/support/plugin/wordfence/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordfence/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordfence/reviews/)

## Tags

 * [memory allocation](https://wordpress.org/support/topic-tag/memory-allocation/)
 * [memory issues](https://wordpress.org/support/topic-tag/memory-issues/)

 * 13 replies
 * 2 participants
 * Last reply from: [mishash](https://wordpress.org/support/users/mishash/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/memory-allocation-errors-in-error-log/#post-10161792)
 * Status: not resolved