Skip to main content

A few thoughts on Golang vs PHP for web development

I have a new project nearing completion which is based on Golang, and with a Postgres backend. TLDR I wanted to add a compiled language to my skillset so that I could produce fast binary executables. I think a well rounded web developer really needs to have proficiency in three types of language:

  • A 'front end' scripting language, such as PHP or (I hate to say) Javascript. You need something that is fast, readable, flexible, hackable.
  • A compiled language for producing blazingly fast and efficient binaries. Golang is a good choice, but there are many options here.
  • A general purpose 'utility' scripting language for data processing, maintenance and glue code. Python is the obvious choice.

If you're not a web developer you can skip the font end and you really just need a compiled language and utility scripting language of your choice. And web developers can get away without a compiled language, but having access to one opens up a lot of options.

I settled on Golang because it is modern, memory safe (mostly) and provides highly efficient built in webserver functionality. Goroutines have a tiny memory footprint, fast start up time, and low CPU overhead, all from a single small compiled binary. Compared to Apache2 with its endless configuration options and complexity, it's quite a relief to deal with.

And Golang has not disappointed me. The efficiency gains are real and will allow me to deploy onto minimal hardware, thereby directly saving money. Even on a Raspberry Pi 5 development box (yes, really) my web app runs like lightning and has shockingly low CPU and memory footprints.

But there is a downside, and this is where PHP has the advantage: Maintenance. If a PHP site has a problem you can often login while it's running, poke around a bit and fix it, without much concern that you will torch the entire system. The files are human readable text, so modifying one or reverting a bad change is basically instant with limited blast radius. You can do emergency maintenance on the road from a tablet or even a phone.

With Golang (and ok I'm using Docker and Templ), the most trivial of changes to a template requires a rebuild of the binary and container. It's still pretty fast, say a minute or two, but you can't tweak a live production site. Not such a big hassle, but it does require pre-planning and a properly set up test or staging environment.

So where to from here? For larger workhorse web apps and CMS systems I think PHP is a more admin-friendly choice and I'll probably keep using that. But for small sites and utilities, or where efficiency and hardware costs are key concerns, Golang is awesome.

Copyright, all rights reserved.