I dont know how/why this happened. I was working on my site over the weekend and it was fine. When I came into the office this morning, I went to the site and got this:

Fatal error: Allowed memory size of 146800640 bytes exhausted (tried to allocate 57 bytes) in public_html/wp-includes/rewrite.php on line 1561

I searched and found some articles that offered solutions, but none of them worked for me. What I noticed that the file that is effected is usually different in each case. Mine happen to be the "rewrite.php" file. That might help. Other than that Im stumped.

I know the customer complaints are coming. Hopefully I get it fixed soon.

What would be causing this, so I know not to repeat it (if I did cause this). Can anyone help with this?


I defined the memory limit in the wp-config.php to 64M and the line reference in the error is now 836 instead of 1561.

This is the code for line 836:

if ( is_array( $uris ) ) {
            foreach ( $uris as $uri => $pagename ) {
                $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
                $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));


I fixed the problem. The problem was somehow related to the permalink settings. Im using the CouponPress theme for wordpress. After increasing the memory limits, as suggested in most of the solutions (php.ini, wp-config.php, etc), I simply changed the permalinks to default and then back to my custom permalink. Everything seems to be back to normal. Why did this happen? I have no idea. All of sudden the error came up Monday morning and everyone was crazy (angry). I WOULD like to know what caused this, so I can prevent it in the future if I can. Thanks to everyone who helped me out with actual solutions.

  • "I was working on my site over the weekend" ... what were you working on; what did you change? Also, what plugins are you using, what theme, what core hacks (if any), and what are you doing when this error occurs?
    – EAMann
    Commented Nov 28, 2011 at 20:10
  • I was working on a custom pagination plugin. But I don't think that would be the problem because after saving my changes, the site was still working AND just in case there were any changes that mightve cause it, I cleared the whole php file and left it blank, but Im still getting the error. And the admin section isn't working either.
    – user1893
    Commented Nov 28, 2011 at 20:38
  • 1
    Essentially, this error crops up because your server is running out of memory to allocate to PHP and WordPress. If you're on a shared host, it could be a poorly configured machine. But since this just started happening, it's likely been caused directly by changes you've made. So without knowing a) exactly what you changed and b) exactly how your server is set up, there's not much we can do. I suggest you find and hire a server/WordPress professional to take a look at your specific situation. As is, this is too localized for the site and I vote that it be closed as such.
    – EAMann
    Commented Nov 28, 2011 at 22:32

3 Answers 3


There really is nothing anyone here can do for you with such limited information. It is obviously something within your recent changes.

If you use a version control system (as everybody really should), I would roll back the changes and then from there slowly re-implement the changes that were causing this error to track it down and get rid of it.


Fatal error: Allowed memory size of 146800640 bytes exhausted (tried to allocate 57 bytes) makes the problem clear in the error message. You're running out resources - php memory.

You can increase the php memory or you can ask the hosting provider to increase it for you.

There are several ways to increase php memory. Some may work for you and others not. If the first method is not working for you, you can try the next.

1.) Setting Memory Limit in wp-config.php - define('WP_MEMORY_LIMIT', "256M");

2.) Memory Limit PHP Directive in .htaccess file - set php_value memory_limit 256M directive

3.) Changing Memory Limit in php.ini - set memory_limit = 256M

4.) Set PHP Memory Limit During Runtime - set ini_set('memory_limit', "256M"); directive

5.) Ask Your Hosting Provider - if none of the above result in increasing your php memory, please ask your hosting provider.

Create an info.php file and add phpinfo(); To check your memory limit open the domain.com/info.php file


Open your wp-config.php and make sure it has the following placed inside of it:

define('WP_MEMORY_LIMIT', '64M');

I've received similar errors and this fixed it.

  • Thanks Jeremy, I tried that but still get the error. The only thing that changed was that the line reference in the error is now 836 instead of 1561. I updated my post with the code for line 836. Thanks a lot
    – user1893
    Commented Nov 28, 2011 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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