Pages with Facebook Comments Are Very Slow

November 01, 2014

I recently moved a website and found that even though everything appeared to be set up exactly the same on the new server as it was on the old one, some pages were extremely slow to load. The only difference was that the new web server has a native IPv6 connection. Surprisingly, the culprit was using file_get_contents to load data from the Facebook Graph API.

PHP is trying to get a file from Facebook have set DNS A records (IPv4) as well as AAAA (IPv6) records:

$ host is an alias for is an alias for has address has IPv6 address 2a03:2880:2110:cf07:face:b00c::1

However, the server at the end of the AAAA record, i.e. the IPv6 enabled server does not understand the URI… but instead of returning something useful like a 500 error it just hangs for ages. This is not a problem for most people because even though anyone can look up an AAAA record, only IPv6 enabled web servers will attempt to connect using IPv6.

So, for IPv6 connected hosts, file_get_contents just hangs at this point and stops the rest of the page from loading. The possible fixes are to either disable IPv6 on the web server running the PHP script (a bit drastic!), or to use curl because it has the capability to ignore IPv6 entirely using the following option:


Hope this saves somebody some head scratching anyway!