PHP ipv6 support in fsockopen()

1.3k views Asked by At

We are using PHP and fsockopen() to check if a host is available. It works great for standard ipv4 addresses, but recently we started adding ipv6 addresses and it fails. According to the PHP documentation for fsockopen() we simply just need to enclose the ipv6 address in brackets for ipv6 support.

fsockopen('[2a03:b0c0:3:d0::14a:e001]', 80, $return_error_number, $return_error, 10);

However, we are always getting:

Network is unreachable

Does the server running PHP need to support ipv6 as well for this to work? Any other gotchas?

1

There are 1 answers

0
Cobra_Fast On

Network is unreachable

This is an error message of the underlying infrastructure and is most likely not produced by PHP itself. It means that the network trying to be reached (in this case the IPv6 global scope) cannot be communicated with. This is usually due to misconfiguration or failure to implement IPv6 by the ISP.

Does the server running PHP need to support ipv6 as well for this to work?

Yes. Very much so. Think of network protocols as languages spoken over phone lines; if two callers don't speak the same language they won't be able to understand each other and hence their information will be mutually unreachable.

There are however services that let you NAT or embed IPv6 within IPv4, maybe even by your ISP. Such offers are usually titled "IPv6 tunnel" or similar. Inquiring about IPv6 at you ISP is usually a good first step - professional server hosters and datacenters will often provide an option to enable or order basic IPv6 through their customer panel.

Check if IPv6 is properly configured for your particular environment or if you want to utilize a tunnel service. If there is no other simple way for you to get global IPv6 connectivity, then you will probably not be able to get your code to work.

A great stackexchange community for server configuration of any kind is https://serverfault.com/ and many questions about IPv6 have already been answered there.