Fixing ERR_CONTENT_DECODING_FAILED in Apache+PHP

Sometimes 3rd party PHP code just refuses to launch. Actually, it happens quite often. If you have just copied it and it worked – it’s a good sign. This time it wasn’t the case.

After going through all the initial steps, it looked like it should work, but instead of usual runtime errors this PHP application, running on Apache 2.4.9 & PHP 5.5.12, started showing this:

ERR_CONTENT_DECODING_FAILED

ERR_CONTENT_DECODING_FAILED
Error 330 (net::ERR_CONTENT_DECODING_FAILED): Unknown error.

Google Chrome’s Developer tools –> Network looked empty for quite some time, but after a really long wait here is what I’ve got:

google developer tools apache php 330 timeout compress gzip

Quick googling explains that this error is shown when HTTP response headers claim that the content is gzip encoded, but it isn’t. Other sources say that this may happen when plain-text content is added before/after encoded content. So proposed solution is to disable content compression.

There are different examples, it mostly involve writing something like

or

to your .htaccess file. I was still getting same error, it made no difference for me.

What helped

Adding zlib.output_compression = On to php.ini helped me. Issue was solved.

Likely source of issue

I am not certain where and how compression was forced to be enabled (this is a big black box legacy PHP sources), but I have noticed it only throws this ERR_CONTENT_DECODING_FAILED exception when there are debug errors on the page.

Literally, setting display_errors = Off in php.ini fixes the issue as well. In my case it was some E_STRICT messages, so setting error_reporting = E_ALL & ~E_STRICT there to disable displaying E_STRICT errors works too.

Now when this behavior doesn’t look like some random magic, I feel like I’m in control again, therefore I may sleep well. It works.

Welcome The Great Russian Firewall

I have just found that my site stefantsov.com can not be opened from Russia. Since I’m not doing anything bad, this was a surprise for me. After digging a bit, thanks to +Fedor, I was able to find the reason behind the blocking.For stefantsov.com I’m using Cloudflare CDN to deliver resources faster all around the world, reduce server bandwidth, get some free optimizations, etc. Cloudflare effectively hides my real IP, delivering all content itself. Currently site’s IP resolves to 141.101.116.129: CLOUDFLARE-EU. In russian blacklist there is some hentai site, that is using Cloudflare as well, resolves to same IP address. It got blocked few days ago, which effectively blocks my site as well.gl hf gg wp no re, да здравствует великий российский файрвол, guys.
[Random In Soviet Russia joke]

Stefantsov Blocked Firewall

 

Google Night Walk in Marseille, France

This is a great piece of art, a nightwalk through the savannah of the night Marseille. This is done using Google Street View engine, but greatly enriched by music, sounds and annotations.

You will usually encounter images like this:

Google Nightwalk Marseille France ArtOne of many sights of the night Marseille

You may love it, you may hate it, but it will not leave you indifferent. Like promised in the very beginning, it will show you the soul of the city. Take a night walk with Google in Marseille, France.

Umbraco 7 MVC performance

Performance always interests me. Now, when I host my sites in Cloud, it interests me even more. Better performance = less money spent.

My current setup: Windows Server 2012 Standard, IIS 8.0, SQL Server 2012 Express, 2 GHz core, 1.5 GB RAM, Umbraco 7.0.3. I have tried first two google pages of “website online stress testing tools” and it’s variations, the best and the only leader there is https://www.blitz.io/, nothing changed here since my previous article. Really great tool.

So, my results (really approximate):

  • ~50 requests / sec takes a 2GHz core
  • ~100 requests / sec takes 10 Mbps
  • ~200 MB RAM per each Umbraco instance (less than 1000 nodes)

More specifics:
I’m testing it on a simple Umbraco site, with less than 1000 nodes. It only have uBlogsy package installed, and my custom .dll with few extensions. Page I’m testing is 2nd level deep in Layout, it have about 10 Partials, but every one of them is CachedPartial with 60 seconds cache time (more than enough for the test). Uncached part of page contains moderate amount of logic. In real world you can’t expect all the code to be 100% optimized and always be perfect. Code happens. But if I remove that code, I get up to 160 hits / second:

Content-only page with no logic at allContent-only page with no logic at all, this is unlikely to happen in real life

 

Here is how same page with absolutely no logic looks when I set my cloud PC to have 2x 2GHz cores (twice as much CPU power):

Content page with no logic, 2 coresSame content page with no logic as above, but this time with 2x cores of 2GHz

 

Back to real life. Page with moderate amount of logic. How will it act on 10 cores?

Server Task Manager 10 CoresWindows Server 2012 Task Manager during stress test, 10x 2GHz cores

 

10 Core Moderate Logic PageStress test image for page with logic, server is 10x 2GHz cores

You can see, Umbraco scales pretty much linear.

Whether this numbers big or not is up to you to decide. Most sites won’t ever experience this many visitors anyway: 50 hits per second translates into up to ~4 000 000 views per day.
And it scales linear with CPU: want 40 000 000 views per day? Throw 9 more cores and you are fine. Want 4 000 000 000 views per day (do such numbers even exist?) and your server can’t scale that high? Scale horizontally: add few more servers and do a load balancing. I’ve never seen this myself, but Umbraco claims it supports load balancing and it works well. Exciting video about Umbraco serving Red Bull Stratos project, how they did it:

 

One more trick to serve many static pages at once: OutputCache. With Umbraco MVC is is really easy to enable and it gives more than 10 times boost. Here is image for 1x 2GHz core and OutputCache enabled:

Umbraco Output Cache Performant ServerUmbraco 7.0.3 MVC with [OutputCache] attribute specified on hijacked route controller action. Server side.

 

Umbraco Output Cache Performant Stress Test[OutputCache] stress test results. 1x 2GHz CPU core.

 

Now this is what I call good performance! Important thing to remember here is network bandwidth. This example alone was generating more than 70 Mbps of outgoing traffic. And stress test is not requesting any resources like CSS, JS or images. If you are about to have this much real users, you’d be using much more bandwidth!

Code:

This is Umbraco route hijacking. In short words, you create a controller class with name that starts with your Document Type alias and ends with “Controller”. It’s Index action is called to display page of this document type. Do whatever you like with it. In our case, apply OutputCache attribute.

Also, like mentioned in comments to this article, one could take a look at Donut Caching, here is a nice article on MVC Donut Caching. It promises to solve caching problems for pages that have changing parts (like Logged In user partial). Would love to hear about successful Donut Cahing use cases on Umbraco.

jStepper: convenient numeric input text plugin

jStepper is a nice and really useful jQuery plugin that, once applied to a text input, only allows digits or numbers to be entered in it.

Setting it up as easy as

Look at jStepper in action at Hearthstone Calculator tool I’ve made recently. Here is the code that I’m using for hscalc:

jStepper homepage is handy, you can see all the options and apply them right away.

Not much else to be said. This tool just works, as intended. You would also like to know that author behind it, +Martin Kruse, is nice and helpful guy. Collaborated well on a little bug I had for my corner case, accepted my pull request.