A little bit about filesize units (KB, MB, etc)

I helped my 14-year old son with his homework today and there was a question about how to convert from Kilobytes (KB) to Megabytes (MB). My instinct was to tell him to divide by 1024 (the more technically accurate version of a KB) but we both decided the answer they wanted was 1,000.

In my work creating websites and web applications we sometimes report on filesizes, usually in human-readable formats such as reporting on the filesize in MB. For example, a document listing may include the filesize to give the user an idea of how long a download may take.

So this made me think about how we calculate human-readable versions of filesizes on websites. In the past we tend to divide bytes by (1024 * 1024) to get to MB. Now I wasn’t so sure. So I had a bit of a read around.

Binary and decimal units

Historically computers have always used binary units, since that’s how computers work. At their simplest level everything is either a 1 or a 0.

Traditionally a kilobyte is 1024 bytes, a megabyte is 1024 kilobytes, a gigabyte 1024 megabytes, and so on. This is called base 2 (or binary) since these numbers are all a power of 2 (1024 = 210 bytes).

As computers became more mainstream people naturally assumed a kilobyte meant 1000 bytes, a megabyte 1000 kilobytes, since base 10 (or decimal) is what we’re used to as humans.

So we currently have two ways to describe a kilobyte: decimal (1,000 bytes) or binary (1,024 bytes).

Messy real world definitions

There seems to be a lot of confusion in computing with developers often using the “more accurate” binary unit to calculate file sizes and others using the decimal unit.

In the early days of the web most computers used binary units to report filesizes. This has changed over time.

It turns out hard drive manufacturers refer to storage sizes using the decimal format. So a 100 MB hard drive is actually 100 * 1000 KB (rather than 100 * 1024 KB). This results in a smaller storage space than if you used the binary unit to calculate storage size (e.g. 1 GB = 1,000,000,000 bytes in decimal or 1,073,741,824 bytes in binary, this is around 7% smaller). Good for sales, less good for the consumer.

There’s even a Wikipedia page on the confusion this has created. Interestingly this notes that the US legal system has decided “1 GB = 1,000,000,000 bytes (the decimal definition) rather than the binary definition.”

There are also standards. IEC 80000-13, published in 2008, defines a kibibyte (or KiB) as 1024 bytes and a kilobyte (KB) as 1000 bytes.

According to the Institute of Electrical and Electronics Engineers (IEEE) the decimal format should be used as standard unless noted in a case-by-case basis (see Historical Context on this NIST reference page). This is also known as SI, The International System of Units, which defines the prefix killo as 1,000.

So technically you should write KiB if you mean 1024 bytes. But it turns out very few people do this, and everyone just sticks to kilobytes or KB whether they mean decimal or binary.

So today we’re still stuck with some people using KB = 1024 bytes and some people using KB = 1000 bytes. Yay!

However, clearly most people don’t care. And storage sizes are so large now most people don’t really notice the differences. Unless you’re a computer or web engineer who has to do calculations on this sort of thing.

What do modern operating systems use?

Well, here’s where it gets interesting.

In my early days of web development (which started around 1999) I used a Windows PC, these days I use a Mac. While hard drives advertised their size in decimal units, Windows itself reported filesizes in binary. So in practical terms a 1 GB hard drive actually had less space for file storage on it (around 953 MB available space). I remember that annoying me!

In the early days of Macs and smartphones they also reported filesizes in binary units. So it made sense that most people used binary units to report filesizes on web apps.

From 2009 Mac switched to reporting file sizes in decimal (with Mac OS X Snow Leopard, presumably in response to the IEC standard). This didn’t happen until 2017 for iOS and Android.

Today Ubuntu Linux, Mac OS, iOS and Android use decimal for file storage sizes. Windows, as far as I’m aware, still uses binary units. However, to spice things up Microsoft’s cloud office service 365 uses decimal units when referring to cloud storage size!

So today if you have a file which is 500,000 bytes in size this would report as 488 KB (binary) on Windows and 500 KB (decimal) on Macs, Ubuntu Linux and modern smartphones.

What works for users?

Which is right? To be honest, I don’t think that matters. What’s more important is which makes more sense for your users.

Most web development resources still tell you to use a binary units to convert between file storage sizes (e.g. bytes to KB).

But as you can see, almost everyone else uses decimal units in the real world (except for Windows OS – but even Microsoft uses decimal for their cross-platform 365 service).

When building web applications it’s always best to do what is best for your users. So now, most of the time I think it makes more sense to report filesizes using decimal units rather than binary (so 1,000 bytes = 1 KB). Which is the opposite to what I thought before I started writing this post!

Just to make things fun, other measurements which use kilobytes actually do use binary units consistently, computer memory (or RAM) being the obvious example. As far as I know every system out there uses binary units for measuring memory!

If this is all too much, I’ll leave you with the excellent xkcd web comic, kilobyte edition:

Error monitoring tools and UK/European data storage for GDPR compliance

At Studio 24 we work with a lot of government and public sector clients, who are understandly keen to comply with GDPR and are therefore careful about where data is sent and stored.

There is a strong preference to use services that store all data within UK or the European Economic Area (EEA).

This is an issue for many SaaS products since most of them store data in the US or Canada. While there is the EU-US Privacy Shield agreement this has become uncertain after Brexit.

Where possible, we aim to use EAA or UK hosted data for public sector digital services. Where that’s not possible we can use non-EU hosted data for services, but we need to justify this with our clients.

Two tools we currently use for error reporting and monitoring are Bugsnag and Usersnap. After my review I discovered Bugsnag is hosted in the US, though Usersnap is hosted in Europe. A summary of my research on data storage locations is below.

In addition I’ve also added notes on where you can strip indentifying user data from external data storage. This can be helpful for data privacy.

Hosted in EAA


Data hosted on AWS in Europe (Germany or Ireland). GDPR docs are a bit sparse but you can request more details via email. It’s not really possible to strip data via Usersnap due to how it works (on demand screenshot tool rather than automated monitoring).

New Relic

It is possible to select EU data storage when setting up your account. New Relic publish information on security and privacy. HTTP parameters are not logged by default to avoid logging user data.


You can use the EU site to ensure all data is stored within the EU. View GDPR docs.

Hosted in US only


Data hosted in USA. GDPR documentation is available on request.


Data hosted on Google Cloud in USA. Bugsnag does have a detailed Data Processing Agreement and some examples on how to delete user data for data deletion requests which is nice to see.


As far as I can tell data is stored in USA.


Data is stored in USA. Lots of options to exclude sensitive data.


Data is stored in USA. You can remove sensitive data.


Data is stored in USA. There is some docs on scrubbing data in JS.


Data is stored in USA. See data privacy docs. Sentry has data scrubbing tools.

Weeknotes: 31 Jan

I’m going to try to start keeping weeknotes. It’s a good way to reflect on the past week, get into a regular habit of writing, and is a nice way of working in the open.

My past week has been pretty busy, in general January has been a pretty crazy start to the new decade with lots going on! Monday and Thursday in London for various client meetings in and around Westminster. We’re currently working with the University of Cambridge on a site for their Alumni magazine and a range of WordPress sites for Parliament.

Had an exciting potential new client call on Tuesday, more on that later!

Had a meeting for the Cambridge Film Trust. We’ve going through a lot of planning for the 2020 festival at present.

I took a look at how to multilingual properly in WordPress using a multisite approach. So far initial work is showing this is a far more sane way of doing it in WordPress. Our previous efforts had included tools such as WPML which we found can get into real difficulties once you start having more complex content.

We’re currently recruiting for a new web developer, so spent some time going through CVs and emails from candidates. It’s a pretty time consuming process, but essential to do properly to get the right people.

Ended the week with a board game night at work, where we played Dixit, a fantastic card game I’d not played before. One person plays the storyteller, chooses one of their cards (with beautiful imagery), picks a phrase, and everyone else has to choose which of their cards best fits. The idea is to guess which card is the storytellers. Will have to buy it for the family to play!

Local development with Valet

I’ve used MAMP Pro with my team for local development for many years. It’s a convenient tool, but it’s often slow (especially the CLI) and often hangs or crashes. I’ve been looking around for alternatives for quite some time, so after it was recommended by Zuzana thought I’d take a look at Laravel’s local dev environment Valet.

Installing Valet

Valet installs a lightweight set of tools to run websites on your Mac via Homebrew. This feels like a good approach to me. I’m not sure we really need the complexity of virtual machines, the code we write tends to work fine on a Mac. Having tools locally installed via Homebrew is fast and convenient.

I started by updating Homebrew to make sure my local packages are up to date:

brew update

Then installed Valet globally via Composer, and installed it:

composer global require laravel/valet
valet install


Next I need to install MySQL since this will no longer be available via MAMP:

brew install mysql@5.7
brew services start mysql@5.7

This has installed MySQL, I now want to secure the local root password (by default it is empty):


(please note the path to mysql_secure_installation may change depending on your version of MySQL).

Next, I want to connect to the database to install a copy of my own blog WordPress database for local testing. We use the excellent SequelPro for managing MySQL.

It’s easy enough to connect to localhost using the details:

  • MySQL Host: 127.0.01
  • Username: root
  • Password: (the secure password I set above)

This worked fine, I created a new database for my local test site and imported a recent SQL backup.

Serving a site

The default method to serve sites in Valet is to use valet park to serve all sub-folders in ~/Sites as websites via URLs in the format folder-name.test

For example, http://wordpress.test/ would serve a website with the document root of ~/Sites/wordpress

This isn’t really how we work, most projects have a “web” sub-folder inside a project to allow for files outside of the document root. So for setting up local sites I’ll need to use the valet link command to set each site up manually.

To create a link from ~/Sites/simonrjones.net/web for the host simonrjones.test it’s simple enough:

cd ~/Sites/simonrjones.net/web
valet link simonrjones

I can verify the sites setup in Valet via:

valet links

The final step is to ensure WordPress knows about this new local test URL, otherwise WordPress has a habit of redirecting to what it thinks is the correct blog URL.

I use the multi-environment config on my personal blog so this is easily achieved by changing the ‘domain’ value for the ‘development’ environment in the file wp-config.env.php

 'development' => [
        'domain' => 'simonrjones.test',

I can test this now via the URL http://simonrjones.test/ – which worked first time!

Testing with a more complex setup

Next, I tried this with one of our client’s WordPress multi-site installs, which is a little more complex. The site is hosted at WP Engine so it uses the standard wp-config.php setup (not multi-environment config).

CD’ing into the project folder and running valet link is enough to make the site run from a local *.test URL. However, trying to access the site doesn’t work and WordPress multi-site redirects the request to what it thinks is the correct URL.

I have WP CLI installed, so I tried to use this to update old site URLs to the new *.test ones, but I couldn’t see a way to reliably do this for multi-sites. So I went back to straightforward SQL!

UPDATE wp_options SET option_value='http://clientdomain.test' WHERE option_name='siteurl' OR option_name='home';

UPDATE wp_site SET domain='clientdomain.test' WHERE id=1;

UPDATE wp_sitemeta SET meta_value='http://clientdomain.test/' WHERE meta_key='siteurl';

UPDATE wp_blogs SET domain='clientdomain.test' WHERE blog_id=1;
UPDATE wp_blogs SET domain='site1.clientdomain.test' WHERE blog_id=2;
UPDATE wp_blogs SET domain='site2.clientdomain.test' WHERE blog_id=3;
UPDATE wp_blogs SET domain='site3.clientdomain.test' WHERE blog_id=4;
UPDATE wp_blogs SET domain='site4.clientdomain.test' WHERE blog_id=5;

UPDATE wp_2_options SET option_value='http://site1.clientdomain.test' WHERE option_name='siteurl' OR option_name='home';
UPDATE wp_3_options SET option_value='http://site2.clientdomain.test' WHERE option_name='siteurl' OR option_name='home';
UPDATE wp_4_options SET option_value='http://site3.clientdomain.test' WHERE option_name='siteurl' OR option_name='home';
UPDATE wp_5_options SET option_value='http://site4.clientdomain.test' WHERE option_name='siteurl' OR option_name='home';

In addition I had to set the wp-config.php setting to the default site URL

define('DOMAIN_CURRENT_SITE', 'clientdomain.test');

Finally, I had to setup additional URLs to serve the multi-site URLs in Valet:

valet link site1.clientdomain.test
valet link site2.clientdomain.test
valet link site3.clientdomain.test
valet link site4.clientdomain.test

The above appeared to serve the multi-site install from the different URLs. However, when I attempted to login to WordPress I was presented with a white screen of death.

I tried valet log and viewed the Nginx error log. Nothing. I refreshed the page a few times and WordPress came up. Navigating around most WordPress admin pages seemed to work, but I got the occassional slow page load or white page. On the front-end pages in sub-folders often seemed to not work on the first request. This is a little disoncerting. This may be caused by the complex WordPress setup, one of the installed plugins, or simply the fact it’s using Nginx and we’ve built these sites to work on Apache. It’s something I’ll have to look into.

Next steps

Valet certainly seems to be a useful tool and one that is very quick to setup. Things I’d like to look at next..

  • Review the secure HTTPS option in Valet
  • Take a look at Valet+, though it looks a little out of date compared with Valet.
  • Can we customise the webserver used so it more closely matches our production environment (we use Apache instead of Nginx FastCGI)?
  • Is there a WP CLI plugin to help change multi-site URLs? If not, we should write one!

If we can use a lightweight dev setup such as Valet it would be nice. Though as with everything in tech, it’s clearly not completely plain sailing! MAMP Pro is certainly easier to use and setup, though it’s the speed (web requests and CLI) which I’m starting to want improved more than MAMP appears able to offer.

Creativity, Playdate and making things

It was with some delight I opened this month’s Edge magazine which I found on my table this evening. This month they have an exclusive on a nifty new handheld console built by software developers Panic called Playdate.

From the article, Playdate looks awesome. It’s a a cute yellow handheld with a high-quality LCD screen, simple controls and an intriguing crank, designed for fun gaming experiences written by indie developers. It looks like nothing I’ve played before. The concept seems pretty crazy, but that seems to be the point.

Edge #333 - Playdate handheld console

With a series of fun, creative, offbeat games released every Monday over wifi once you boot the Playdate up, the concept seems to be genuinely original and born out of a desire to just have fun and make stuff. I can’t wait to get my hands on one!

If you’re a fan of gaming the Edge article is well worth the price of the magazine. Reading through a few things stuck out for me.

I’ve been aware of Panic for many years. We use their software at Studio 24 (their excellent file transfer tool) and I’ve always been struck by their attention to detail and quality of design. I eagerly played through Firewatch when it was released on the Playstation 4. A fantastic game beautifully designed, full of atmosphere and good storytelling. The sort of game I really enjoy.

From the Edge article, Cabel Sasser (co-founder) explains what he believes was the origin moment for the project. He talks about Panic being a 20-person company with revenue around the two million dollar mark. He woke up one morning with “a bit of an existential crisis”. He had a profitable, independent company without external investors, with a team that could put their hand to a range of things – not just the same sort of work they’ve been focussed on for so long.

I realised we don’t have to keep doing the exact same thing that we’re always doing – this ceaseless develoment-and-support cycle. We can do some weird things too, as long as we’re not betting the farm. If we have this chance, we should probably start doing some things that take us to new places. Maybe they’ll work, maybe they won’t. But if we’re not doing that, we’re just wasting out lives.

Cabel Sasser, Co-founder, Panic

This kinda resonates with me. I run a digital agency, not far off the same size and revenue as Panic. I started as a creator too, hacking together web pages and making software. Making things has always been part of my make-up. But with running an agency that often takes a back seat, and spare time pretty much disappears if you’re not careful. It’s fantastic to see other companies of a similar size spin out internal projects into something so impressive.

Another lovely quote is:

Running this company now, I feel almost like a different person. I feel like a huge part of that is finding again how important it is to me and for everyone here to just make things, and be proud and excited about it.

Cabel Sasser, Co-founder, Panic

It’s a bold and exciting move for Panic, but one that I’m sure will give them new opportunities and rewards. There seems to be a real movement for more interesting, playful gaming at present. I hope Playdate does really well.

I’ve seen this in other companies recently too. Only this week I read that the excellent WordPress agency Human Made released Altis, their own “next generation” CMS platform built on top of WordPress. From my brief review it looks like a really interesting set of content and development tools to make creating engaging websites way easier. It sounds like an interesting venture for Human Made.

It also reminds me of Brendan Dawes’s talk at New Adventures about creating things, hacking together technology and making new things. (if you’re not aware New Adventures is a superb conference on digital creativity, ethics, inclusion and other essential topics)

Digital is so powerful and teams that work in this industry end up with such a variety of skills that can be put to great use. Studio 24 is twenty years old this year and I hope to be able to make more time for creating things with my fantastic team. I’ve started already with a foray into building sites with Headless CMSs and some tools I hope we can spin out into a viable open source project in the near future (which I also hope will spark off some interesting talks I can do at user meetups & conferences).

I’m also trying to blog more these days. Blogging on your own site seems to be coming back into vogue, I think it’s simply a nice way to note down your thoughts to help inspire and motivate. As Field Notes neatly puts it: “I’m not writing it down to remember it later, I’m writing it down to remember it now.”

Adding a Staging environment to Symfony 4

Environments in Symfony

We use Symfony a lot at Studio 24 for building modern web applications. Our normal setup is to have a local development environment, a staging environment for clients to test code, and a production live site.

By default Symfony supports the following environments:

  • dev – (development) intended for development purposes, can be used locally or on a hosting environment to test your application
  • test – (automated tests) intended for use when running automated tests (e.g. phpunit)
  • prod – (production) intended for the live web application

Ideally we would have a third web environment to represent staging, which is what we use to preview functionality before go-live. So that’s what I set out to do.

Adding a custom environment

I want to call my new environment stage to represent staging, since Symfony already uses shortened versions for other environments.

It turns out you can just add any old environment name and Symfony recognises this. So setting the new environment locally is really only a matter of updating your local environment settings file .env.local (you can also set this via actual server environment variables).

# Website environment

Environment configuration

Symfony loads environment variables from .env files. It uses the .env file for default values, then loads the .env.{environment} file for environment-specific settings. Finally, it loads the .env.local file for sensitive variables (e.g. API keys or database credentials – this file should not be committed to version control).

To help keep track of my staging environment variables I created a file at .env.stage to store these.

Package configuration

Different packages use YAML config files in the config/packages folder. I created the folder config/packages/stage/ which is used to store package configuration for the stage environment. It’s possible to inherit values from another environment via the imports key, which is really handy. Here I’m importing the prod settings for the stage environment.

# config/packages/stage/monolog.yaml
- { resource: '../prod/' }

Composer packages

One gotcha is your PHP code may depend on a library that is loaded by Composer locally in your dev environment (via require-dev), but does not load on stage or prod.

When I first tested the above code, it crashed since Monolog was not found (this is used for logging). It turns out Monolog was loaded in my local dev environment via symfony/debug-pack which is setup to only install on require-dev in my composer file.

This simple composer require command quickly fixed it!

composer require symfony/monolog-bundle

Debug mode

Debug is enabled by default for dev and test environments, and disabled for prod and any new environments.

Normally I’d recommend not displaying debug mode for a staging site, since it is supposed to be an environment to preview the site and should work in the same was as production.

However, you can enable debug and the Symfony debug bar for your new stage environment. First set APP_DEBUG in your .env.local file:


Next, ensure the debug bundles are enabled. Edit config/bundles.php and ensure the WebProfilerBundle and DebugBundle are both enabled for the new stage environment.

    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'stage' => true],

Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'stage' => true]

Finally, create the following config files:

# config/packages/stage/debug.yaml
- { resource: '../dev/' }
# config/packages/stage/web_profiler.yaml
- { resource: '../dev/' }
# config/routes/stage/web_profiler.yaml
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt

resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler


That’s it! It turns out it’s very easy to setup new environments for Symfony 4, most of the work is in enabling any bundles you require and ensuring the right config files are setup for your new environment.