I have been working more and more with WordPress lately, and since I am into technology, I would have to host it myself. Right? 🙂 Anyway, I recently ran into an issue that took me a while to figure out. Well, almost fully figured out. At least I have mitigated the main issue. Here is it…
I was noticing that my page would load at a decent speed, nothing to cause alarm. However, when I would access individual pages, they would sometime (usually) take 15 to 20, and sometimes longer, seconds to load. I would confirm the same by using
curl to request the page. The odd thing I noticed doing this, was that only part of the document was returned, and then there was a long pause, and finally the rest of the document came.
When this first started happening, I had suspected maybe there was something wrong with my nginx proxy settings, since I was passing PHP requests off to PHP-FPM. I tweaked pretty much every setting I could find and nothing helped. Then I started looking at PHP settings, maybe there wasn’t enough memory and it was buffering to disk. Nothing helped there either. I had other WordPress sites as well. Some were exhibiting the issue and some were not. I figured the issue had to be somewhere in WordPress, but wasn’t sure where yet.
I started by deactivating a bunch of plugins on my site to see if there was an issue there. It didn’t seem to help, although I could have just been a fluke, since sometimes the pages would work fine. This led me to believe it might have been network related somehow, but since the pages would still hang for a bit during a
curl request I had suspected that it might have been more of a backend thing. It took some digging, but I finally searched for the right terms in the big Google, and case across an article that helped out, https://deliciousbrains.com/wp-migrate-db-pro/doc/wp_http_block_external/.
After I implemented this change in my WordPress blog, pages were loading lightning fast again. The only word of caution I should use is that this blocks all external requests, including plugin calls and updates, so you will want to combine this change with the
WP_ACCESSIBLE_HOSTS setting which is also mentioned in that page.