Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I love FlatPress, or at least I used to, but specifically I love the idea of a no-database Blog/CMS system. Since 2013, I've been running and making changes to this system, as evidenced by many a post on the topic. In fact my installation of FlatPress has got so far of tangent with all the hacks and customisations I've added to it that I'm not sure if it can really be called FlatPress any more. Yet the core of FlatPress remains and it has a dirty secret. It doesn't scale well with heavy loads.

If you just want to see the final code, scroll about half way down, otherwise stay on for a bit of a babble first... 📣

On the whole, FlatPress is not terrible in terms of performance and I haven't had many issues with it. However lately I have been noticing some stability problems as my Blog increased in popularity and the number of posts grew. Things like corrupt indexes, resetting post view counts, slow response times, etc. And then, I wrote a story which catapulted my traffic volumes to 50x their usual. And my server went down. Not once, multiples times, there were several hours of excruciatingly slow page loads and people resorted to using Archive.org copies of my story. That's when I knew I had to do something.

Caching Generated HTML

My first thought was to use memcache to keep generated HTML pages in memory and serve those instead of generating HTML every time a blog post was requested. Simple idea, but I didn't want to go through the motions of setting up memcache in MAMP. So I fell back to using APC as it required no setup and I knew that I could enable the APCU extension on my webhost.

Looking at index.php, I could see that the Smarty::display() method was used to render and output the content of a page/post. Simple but effective and I thought I would be done with this very quickly.
function index_display() {

The trick was of course to switch to the Smarty::fetch method, cache that output, and serve cached output as required. The cache key was based on $_SERVER['REQUEST_URI'].

Well that approach worked. In a way. However, it only worked in the case where I was caching blog post pages. Everything else like category listings, the home page, sitemap, etc were only partially cached. For some reason only part of the HTML was being generated by Smarty and the rest - well it was being sent to the browser from some other part of the code (I didn't track down where exactly, I did look and what I found were horrors so I stopped looking 😅).

Adding a Cache Handler to Smarty

So then I decided to try a different approach by implementing a Smarty Cache Handler that would work transparent to FlatPress and at least in theory I would not have to worry about the rest of the code base. Well the cache handler worked...for blog post pages only. This indicated that FlatPress was doing something bad deep inside its core. Back to square one.

Continue reading...  

, , , ,

I recently started having issues with the admin interface of a website I run and decided to check the browser console to see if any errors were being displayed there. There were and among them was an error stating that a JavaScript map file being loaded (and failing) that I did not recognise. This meant that the actual JavaScript file itself was already loaded via my website. This set off all sorts of alarms for me and I started to dig in further.


I checked the file system for any suspicious files, there were none. I checked the source code and templates for evidence of anything that has been added, there was nothing there. Yet all my pages were being served with the following <script> injected into them just before the closing </html> tag...
<script>'undefined'=== typeof _trfq || (window._trfq = []);'undefined'=== typeof _trfd && (window._trfd=[]),_trfd.push({'tccl.baseHost':'secureserver.net'}),_trfd.push({'ap':'cpsh'},{'server':'xxxxxxxx0000'}) // Monitoring performance to make your website faster. If you want to opt-out, please contact web hosting support.</script><script src='https://img1.wsimg.com/tcc/tcc_l.combined.1.0.6.min.js'></script>

Of course that comment in the script was a give away of what was going on but I didn't immediately want to believe that the website host itself would be injecting a JavaScript script into my website without my consent! Turned out that's exactly what GoDaddy was doing and they justified it as collecting metrics to improve performance.

The technology that's in use here is called Real User Metrics and GoDaddy has a page about it here - Why am I signed up for Real User Metrics?. If you happen to be a customer in US (which I am not but the website is hosted in a US data centre) then you are automatically opted into this service and all your website's pages will have this JavaScript injected into them.

Continue reading...  

, , ,

A few months ago I built the Dark Knight Bat Signal Kit from Fascinations. Now that we've rolled over into a new year, I thought that there was no better way to kick things off again but to build a complimentary kit from the Batman kit series - the Batman Movie Batmobile. This kit is complex but looks very slick and has a surprising amount of surface detail (with a large portion of it on the bottom of the car). It's not a kit for a beginner and is very satisfying when completed.

The end result is spectacular...

The packaging for this kit feels a little different to the usual Metal Earth style, but I like it. It's nice and clean and shows off the model well.

IMG_2272.jpg IMG_2273.jpg

This is a two-sheet kit and it comes with two double-sided instruction sheets. Don't let those big parts fool you though, there is a huge amount of small components too. It took me around 6 hours to put together. There are some parts that are colour coded, which I quite like as it makes duplicates much easier to pick out.

IMG_2274.jpg IMG_2275.jpg

So lets get to the assembly! The bottom of the car was first in line. This is where a lot of the detail was. Surprising really since this part of the car is not going to be seen when it's on display but very cool that so much detail was put in. The bottom section had one major piece to which all the detail pieces attached to and then there were five extra sections that made up the front, two sides and the two rear wheel areas.

IMG_2277.jpg IMG_2278.jpg

Continue reading...  

, ,

2018 has been an eventful year. Between some major accomplishments at work, getting engaged, starting a new website and decommissioning a blogumentary I've been working on, I was able to grow Igor's Blog with a good collection of popular and informative content. So now it's coming towards the end of the year and I thought that I need to do a roundup article and then take a break until 2019. Next year will also see changes in posting frequency and style as I reshuffle some of my priorities, more on that later.

First lets see what Google Analytics tells us about traffic. In 2018 I had around 500k page views, which is up by around 40% from the previous year's figure of 350k. There were a few outstanding articles that contributed towards that increase. The month-by-month difference wasn't as extreme, but still showed a good amount of growth. This is a really good result considering that the posting frequency was almost halved between those two years. Overall I am happy with the increase in readership.

So more people are reading, that's great, but what have been the developments to drive it? Well this year I was approached by Fascinations/Metal Earth to start reviewing their kits. These posts saw a good amount of popularity throughout the year and I intend to continue publishing more reviews in the future. I've also stepped up the amount of articles I wrote about WebLogic and Programming in general. Even though I write more articles about Java, my dabbling with JavaScript hasn't gone unnoticed. The articles on GameBoy and Neo Geo Pocket, as well as other sorts of modding were quite popular too.

It's been a mixed bag of new content, as usual, but I think the critical factor to the growth in readers can also be attributed to me starting to share what I write on Hacker News. Some articles were so widely shared that my server went down a few times over the year! I know this is an issue in the Blog software I'm using and is something I plan to address over the holiday season - there'll be an article on that in 2019!

Lets talk have a look at which articles have been the most popular this year. I didn't know my readers were so into Penny-Farthing model kits, but for some reason Riding Tall - Metal Earth Penny-Farthing Kit got thousands of views. The extremely popular post, My Amazon Interview Horror Story was widely read and shared. I was a little apprehensive about sharing this experience, but having seen how many people commented that they had the same bad experience with Amazon, I'm glad I did. Then my description of the method of data storage I used over at Atari Gamer received quite a lot of attention - Hijacking HTML canvas and PNG images to store arbitrary text data. Every single modding article I wrote was up there too - Hacking the HBQ-i7 TWS wireless headphones to make a Stereo Bluetooth Receiver, Adding a Back Light to a Neo Geo Pocket (not Color) and Modding a Neo Geo Pocket Color with a Game Boy SP Front Light.

Continue reading...