WordPress Times Out With Too Many Pages?
This one had me pulling my hair out for a few days.
I was developing a client site in WordPress. This site had 500 products and I chose to use Pages (instead of Posts) for the products, mostly because it allowed for a better URL structure, especially because there were product categories and sub-categories. The URLs would look nice — www.site.com/category/sub-category/product-name/
No time to read the entire post? Just update your permalinks to /%year%/%postname%/ and that will fix the issue. If your site is running too slowly to edit the permalinks, edit the database directly. I use phpMyAdmin. Search the wp_options table field name for %LIKE% = permalink and edit the value to /%year%/%postname%/
All was going well in development until we hit around 400 pages. Then the site started running reaaaaaallllly slowly, and even timing out with a PHP fatal error like this:
Maximum execution time of 30 seconds exceeded in /wp-includes/rewrite.php on line 835
WTF! Could this be a plugin issue? Or something wrong in our custom coded theme? I didn’t think so… but what else could it be? Surely WordPress can handle a website with thousands of pages, right?
My first thought was “there must be something wrong with the server.” We did have a separate sub-domain for the site dev.site.com so that was a variable worth looking into. Also, I had just started using a new VPS from Host Gator running Fast CGI (I usually run PHP as an Apache module) so that could also be the cause. Fun, I get to figure this out! [sarcasm]
No luck with tweaking the server settings, although Host Gator support does get an A for effort. And I even updated the php.ini memory_limit from 64M to 128M thinking that this could be the root of the issue. Nuts.
Turns out that good ol’ permalinks is the cause of this problem. For those that don’t know, permalinks allow you to customize the URL for your WordPress site. Very useful for search engine optimization (SEO). In classic obscure fashion that us web developers have grown used to (thanks to IE6 debugging and for the truly old skool, Netscape Navigator 4 hacking), the solution is to add something other than /%postname%/ to the start of your site’s permalinks.
I’ve found that both of the following work equally well:
Not only will this bring your many-paged-Wordpress-website back to life, it will not affect your Pages URLs. In this case, the permalink structure only applies to your Posts. Yay!!!
Hopefully this breakdown will save a few hairs on your head. I wish I had found out about it earlier 🙂 Many thanks to the following which helped me out: