Adventures of a Technomancer

Adventures in WordPress Vol. 2 - Analysis & Clean up

Nicole of Bitten By the Travel Bug has reported some issues with her WordPress install but is unsure as to what is breaking. The only message she sees is;

Error establishing a database connection

So into the terminal I dive, ssh-ing into the server it's time to probe logs and run diagnostics.

This takes a while as I soon find out from htop that 100% CPU being used up by Apache, all RAM and swap is being used too. How is this server even functioning at this point?

Apache

Got to stop Apache from taking over

/etc/init.d/apache2 stop

Once that's done I check out /var/log/error.log for any recurring themes. I find mostly timeouts, a few mysql database connection errors and horribly coded WordPress plugins breaking. Those will be the first to go when the purge comes along.

Just to be careful, I run last and cat /var/log/auth.log | grep "invalid user" | wc -l to see if there has been anyone logging in. (Only 1302 attempts today, not bad)

Since this is a small Digital Ocean droplet I'm going to aggressively limit Apache to allow the site to function but not overload the server.

<IfModule mpm_prefork_module>  
        StartServers              1
        MinSpareServers           2
        MaxSpareServers           5
        MaxRequestWorkers         50
        MaxConnectionsPerChild    1000
</IfModule>

And install fail2ban even though the only enabled method of ssh authentication is keys.

apt-get install fail2ban  

Plugins

WordPress is known for being extensible via plugins, unfortunately these plugins had no peer review or standards to be held to. I have found many plugins which use file_get_contents on a long expired domain for whatever reason, leading to an extra 30 seconds of load time.

Plugins can cause trouble, but not all of them are bad. tail-ing error logs to find troublesome plugins makes it easy to identify some, while others need to be disabled through trial and error.

Originally Bitten By the Travel Bug had 33 active plugins, I was able to bring it down to 20, at least 5 of which I believe should not be plugins and should be part of the theme, but that's a job for another day.

Images

Uploading 5mb images and letting WordPress create thumbnails is a good idea in theory, but the WP core doesn't optimise the files for slow connections.

Here is where jpegoptim saves the day. Optimising jpeg files through the command line saves hard drive space and gives the end user less to download for an imperceptibale loss of quality.

1 command and the uploads directory has been reduced by over half. And more can be saved by tweaking the output quality.

$ cd /wp-content/uploads/
$ du -s
754492  .

$ find . -regextype sed -regex ".*/*.jp[e]\?g$" -exec jpegoptim --all-progressive -o -m90 --strip-all {} \;

$ du -s
361112  .  

Adventures in WordPress Vol. 1 - An Introduction

A good friend of mine, Nicole, runs a travel blog called Bitten By the Travel Bug recently came to me with some WordPress troubles. Her WordPress install that deals with just under half a million hits per month is having a bit of trouble keeping up with the demand.

In this series I'll be investigating and documenting my findings, mistakes and fixes in the hopes that future developers - and maybe even future me - will find the information useful even if it only points them in the right direction.

DomoDrone

After a month of maintenance the ‪DomoDrone‬ is ready to fly again!

With a new CCD camera and working OSD I can't wait to let it rip.

Witcher Wi-Fi sensing medallion - Part 5

Circuit cleaning time!

Once you are satisfied with how prototype performs it's time to remove all the wires from the ESP8266.

With a clean ESP8266;

  • Connect VCC to CH_PD.
  • Then connect GPIO15 to GND.
  • GPIO12 goes to the middle pin (B) on the transistor.
  • VCC connects to C on the transistor.
  • E on the transistor goes to positive on the motor.
  • Ground on the motor goes to ground on the ESP8266.
  • Positive battery lead to VCC or CH_PD.
  • Negative battery lead to GND.

Battery cables, transistor and motor all attached in a compact package.

To prevent any exposed connections from touching the medallion wrapping everything is heatshrink is a good idea.

And with that it's all done.

Mounting the motor and wireless module inside a medallion can be done with hot glue or an epoxy resin. I opted for hot glue so I can remove it and make improvements such as CR2032 battery instead of LiPo or glowing LEDs for eyes.

Witcher Wi-Fi sensing medallion - Part 4

Time to start coding!

But not to worry, I have done all of that for you.

Head over to my GitHub repo, click on releases and download the latest one.

From there, unzip and double click on the vibration.ino file to open the Arduino IDE.

Hit the tick icon in the top left to compile and check the code, make sure it has no errors. If it does, raise an issue on the GitHub issues tracker and it will be taken care of.

If everything compiled correctly and no errors were encountered, plug in the RS232 adapter and hit upload.

Once the upload is complete it should execute the code. Create a hotspot on your phone and be sure to turn off all security to make it 'free', just be sure to turn it off when you're done testing.

Open up the console window and watch for output.

Setup done

Scan start  
Scan done  
Open network not found

Scan start  
Scan done  
Open network not found

Scan start  
Scan done  
Open network found - vibrating  

If you see something like this then it's time to produce a cleaner circuit.