Random, PHP out of memory errors on /wp-admin/

I have Apache + XCache + WPMU + buddypress + W3 Total Cache and few plugins.

Generally all is working fine, but sometimes PHP runs out of memory when accessing /wp-admin/ and the culprit line is "always" the same:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 8193 bytes) in /wp-includes/functions.php on line 4455

This is the code from in functions.php around line 4455:

function get_file_data( $file, $default_headers, $context = '' ) {
	// We don't need to write to the file, so just open for reading.
	$fp = fopen( $file, 'r' );

	// Pull only the first 8kiB of the file in.
	$file_data = fread( $fp, 8192 ); // <-- THE LINE !!!

	// PHP will close file handle, but we are good citizens.
	fclose( $fp );

How can php get out of memory when reading only 8 KB of a file?

Anyone has an idea where should I dig?

  • Jonathan
    • The Incredible Code Injector

    I agree with Aphrodite, 64mb is way too low for wpmu and buddypress. And just out of interest, I find that plugins in general hog the biggest amount of resources via the backend. Exec-PHP Plugin comes to mind lol, now back in the day that plugin would bring a site to it's knees.
    Also, if you are on shared hosting (happens now and again) wpmu and buddypress need some power in their corner. I think general recommendation is via wordpress community is anything over 1gb ram with cpanel, apache, mysql queries and all other things requires some muscle. But that various from setup to setup, and how much traffic, users, blogs you have.

  • Timothy
    • Chief Pigeon

    Hey Adrian.

    How can php get out of memory when reading only 8 KB of a file?

    Its not just one file, its the whole WordPress install, any themes and plugins being used, it all pulls from your memory.

    Upping your memory as previously suggested is the way to resolve this error. You could also look at optimising the use of plugins any additional code and themes.

    Thanks.

  • adrian7
    • Flash Drive

    Well I agree with you that 64 MB might be a little too low.
    I have a virtual server with 2 GB of RAM so, would not be a problem for me to increase memory_limit.

    But here's the glitch, why it works most of the time with 64 MB and then suddenly wakes up and asks for more?

    Is there a possibility that other process on the sever is kicking php out... or apache as sometimes I also receive 500 server errors (as they seem to be related).

  • Timothy
    • Chief Pigeon

    But here's the glitch, why it works most of the time with 64 MB and then suddenly wakes up and asks for more?

    More users, more content, more page loads, more being processed.

    Depending on which page you load, more might load there than other pages, more might be going, more might need processing.

    There are a number of reasons which cause this.

    You might not have many registered users, but you could be getting more people viewing the site.

    I don't know your install or your site, so its purely guesses but there are many factors which can lead to memory exhaustion errors.

  • Timothy
    • Chief Pigeon

    Is there a possibility that other process on the sever is kicking php out... or apache as sometimes I also receive 500 server errors (as they seem to be related).

    Please check your servers error logs and let us know what appears in there when the 500 errors occur.

    Thanks.

  • adrian7
    • Flash Drive

    Looking through apache error_log I found quite more of these:

    [Sun Mar 11 06:52:08 2012] [warn] [client xxx.xxx.xxx.xxx] mod_fcgid: read data timeout in 60 seconds
    [Sun Mar 11 06:52:09 2012] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: index.php

    Also increased memory_limit to 128MB, but dees not makes any difference so far. So next I'll take a look in usr/local/apache/conf/php.conf

  • Ovidiu
    • Code Wrangler

    Also increased memory_limit to 128MB, but dees not makes any difference so far. So next I'll take a look in usr/local/apache/conf/php.conf

    jsut checking: are you sure you are editing the right file? did you restart apache and check i.e. with a test file containing: <?php phpinfo(); ?>

  • adrian7
    • Flash Drive

    Well the solution for out of memory was solved with increasing the memory_limit to 128MB. And I also managed to reduce the frequency of 500 errors, which seem to be related to fastcgi configuration. Specifically with:

    IPCConnectTimeout 60
    IPCCommTimeout 60

    Which i have increased to 90.

    But I don't think that's good, because sometimes I am waiting 30 secs or more to load /wp-admin/.

    Other pages under /wp-admin/ load faster, but specifically /wp-admin/ seems faulty.

  • Timothy
    • Chief Pigeon

    The more plugins you run the more content is potentially pulled in. How many plugins are you currently running?

    20? 30? more?

    You could always look to optimise those. Plugins like Facebook related ones might take longer to load as they make external queries and can often do silent loops (within js which you might not actively see) to get and exchange data.

    You could still double the memory allocated.

    Whats your host say about this? Most will probably just shrug their shoulders and point to the cms/blog your using. Other more proactive hosts should give you some pointers to getting things going faster.

    Let us know how you continue to go with this.

  • aecnu
    • WP Unicorn

    Greetings adrian7,

    Just checking if this issue was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

    If so, no need to reply, that's great news.

    If not, or you have any more questions related to this thread, please feel free to post them below including any new symptoms or errors and tick the 'Mark as Not Resolved (re-open)' box below the post area (or else we'll miss it!)

    Otherwise, happy days, glad you got it sorted :slight_smile:

    Thank you for being a WPMU Dev member!

    Cheers, Joe

  • adrian7
    • Flash Drive

    Sorry for being late with my reply. The issue with "Out of memory" error from php was solved, by 128MB setting.

    I also switched from fcgid to suphp for php handler, and thus eliminating mod_fcgid errors. However the impact over speed is significant.

    So, my issues are not all solved, but I guess it's a problem with the server or the network as sometimes when I am trying to access /wp-admin/ the server does not responds back at all and it seems to enter in an ifinite loop or some "black hole" :stuck_out_tongue:. The top command by ssh does not reveal any overload issues neither error_log.

    I am seriously thinking to move to another hosting provider.

  • Timothy
    • Chief Pigeon

    Hey there.

    Just checking in to see how things are going and if you needed anything else in this thread.

    As we have not heard from you in a little while I'm going to mark it as resolved for now. But if you wish then please just reopen it again and we can carry on :slight_smile:

    Take care.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.