Optimize Images to Save Bandwidth and Speed Page Load

A few weeks ago I mentioned the wesley.pl script from GitHub to optimize images, and how I had modified it to keep (or discard) the EXIF / XMP information. Making sure images are as small as possible is important to save bandwidth and improve page load times (and google rank), so I think it’s worth discussing my image optimization process in more detail.

Continue reading


Adobe XMP with an Hierarchical Subject Array in PHP

This morning I had a bit of a challenge parsing Adobe XMP information for images on Underwater Focus. The Adobe XMP is too complex for SimpleXML, and anyway, I only needed a few values — one of them, the LightRoom hierarchicalSubject keywords, is the reason I’m sharing some of the code I wrote.

Using regular expressions to get at single values is quick and easy, but I wanted to create arrays for `rdf:li` values, and split each `lr:hierarchicalSubject` keyword into an additional second-dimension array.

Continue reading


Wesley.pl optimize script for jpeg, png, and gif

To improve page load times (and Google ranking), you should make sure all jpeg, png, and gif files are properly optimized. Instead of writing my own script for jpegtran, pngcrush, and gifsicle, I used Mike Brittain’s Wesley.pl script on GitHub. It works great, though I did have to modify it to change the “jpegtran -copy” parameter it uses — I need to keep the EXIF on larger files, and strip it from thumbnails. I posted the diff on the GitHub Issues page.

Update 2012-12-31 : In case Mike doesn’t merge my diff, with the addition of the --copy=[all|comments|none] command-line argument (see my comment below for more info), you can download the patched wesley.pl script here instead.

Continue reading


Secure Vulnerable WordPress Files and Directories

Recently Jason A. Donenfeld reported a simple vulnerability in W3 Total Cache on the Full Disclosure mailing list, which was picked up by the Security Ledger website, and then posted on Slashdot. The vulnerability is a simple Apache Httpd configuration oversight — plugins often create their own folders under ./wordpress/wp-content/ without considering that directory indexing might be turned on, or that files within that folder are located under a DocumentRoot, and thus available to anyone. Some configuration files are also vulnerable in this way — the wp-config.php file, for example. During the WordPress install, it is recommended that the wp-config.php be re-located one folder above ./wordpress/, to move it out of the DocumentRoot.

Continue reading


Enable Autocomplete for root on Mac OS X

Are you frustrated by the lack of autocomplete in root’s shell on Mac OS X? I’ve tried a few different solutions, and the easiest / simplest I found is to create an /etc/inputrc file (chown root:wheel and chmod 644) with the following text.

"\C-i": complete

The /etc/inputrc file is used by readline — the input-related library used by bash and most other shells. GNU’s readline init file syntax page documents all the available settings, and Gerard Beekmans Linux initrc file page shows a common initrc for Linux.

Continue reading


Autossh Startup Script for Multiple Tunnels

When an encrypted VPN is not available, the next best solution is usually port-forwarding one or more port(s) through an SSH tunnel. The down-side of SSH is that by itself it cannot maintain a persistent connection — network issues may force the tunnel to stop responding, or even drop completely. Autossh is a small front-end for SSH that can monitor the connection, and restart the tunnel if it drops or stops responding. I found that the startup scripts available for autossh on the internet were a little too basic for my needs — I wanted autossh to start multiple connections, and to start/stop each one individually if I needed — so I wrote my own.

Continue reading


WordPress OS Disk Cache Report, Prime and Flush

I wrote a bash script this morning to report the size of WordPress cache folders, the number of files they contain, read each file to prime the OS disk cache, and optionally flush the OS disk cache as well. This might be a script you could execute to email a daily/weekly report of cache folder sizes, or perhaps execute during/after booting a server to prime the OS disk cache, or even on a regular schedule to make sure the OS cache is always primed. The script also has a “flush” argument to sync and drop the OS disk cache, which isn’t very useful (to me) except to see the difference in speed between a clean and primed cache (about 11s vs 0.4s for all websites on my server).

Continue reading


Memcached vs Disk Cache

I recently added some disk caching for MySQL queries, WordPress objects, PHP opcode, and PHP web pages on my server. There are several different caching techniques and applications available, and memcached seems like one of the more popular ones. Right or wrong, it appears to be the default go-to for many developers these days.

Since I’m a SysAdmin by profession (with maybe a penchant for scripting and integration), I tend to have a more “systems” oriented approach — which led me to first consider, and then choose disk caching over memcached. In this post, I’ll outline the reasons I chose disk caching, and why in most circumstances it might be superior to memcached.

Continue reading