Stopping Runaway Processes In WordPress
Ever run into those pesky 503
errors on a WordPress installation, that no matter what you tried you could not seem to resolve, until finally it just resolved itself? And returned again at the most inopportune time? And again and again?!
Well, with a shared hosting environment, the problem could be as simple as PHP running out of memory. It does so relatively easily.
Since it does not clear said memory automatically (not on all server configurations at least - usually it seems to do so periodically), nor shut down (unless the server actually crashes - or resource restrictions on your account force a shutdown), it'll then show you that same 503
over and over.
It doesn't need to be a 503
per se, it can be just about anything.
An unresponsive and slow site. Settings not saving. Resources not loading. What have you.
I've been working with a client that runs on a particularly bad host, where updating plugins usually causes this, due to not only low memory allotance with the host but also missing essential PHP extensions for say compressing site images, so running a WP installation becomes all the more resource intensive a process.
With a better host you wouldn't have memory issues in the first place, and if you did you'd be able to at least mitigate some of them by upping the limit with a line in .htaccess
, wp-config
or php.ini
, but that did not work here. Nor was there any way to adjust memory use on the server.
Their support didn't help either. They tried troubleshooting the issue once, then gladly informed us that the issue had solved itself! And that was fine until I started updating plugins again...
In frustration I looked for some miracle fix, as I've done so many times before, and this time I found this!
Simple fix: Rename your site directory. That's it!
In a moment PHP processes that run amok will be terminated, you'll get a 404
instead of a 503
when you try to load your site (but you'll get the 404
fast - so you know the memory's reset!) and you can rename your site directory back to whatever it used to be, and keep doing what you intended to do, and hopefully this time manage it without issue...
There will be a slight downtime, yes, but to me that seems much better than an unresponsive site for a longer period of time.
Just be ready to rename the directory back again ASAP when the site loads, and make sure there's no security issue with your host in temporarily renaming said directory, or that you by changing the directory name allow access to files you shouldn't allow access to.
Usually there's no such issue. The site just isn't found.
Longterm fix: Monitor your memory with something like this, get rid of plugins that use too much, or go haywire, and get a good cache, so not as much RAM is required each time a visitor loads a page. And pages load even when WP itself is under duress; possibly running out of memory.
You may still run into issues in admin, but hopefully visitors won't ever...
And consider moving to a different host if the above doesn't suffice, that can handle whatever memory use you need it to.
Temporarily though, the fix above really is a miracle cure.