|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48805 IPv6 socket transport is not working
Submitted: 2009-07-05 16:13 UTC Modified: 2009-09-30 20:48 UTC
Avg. Score:4.4 ± 0.5
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:1 (20.0%)
From: carsten_sttgt at gmx dot de Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.*, 6 (2009-07-06) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
31 + 17 = ?
Subscribe to this entry?

 [2009-07-05 16:13 UTC] carsten_sttgt at gmx dot de

IPv6 socket transport is not working in Windows.

PHP is build with "--enable-ipv6" and you can see this in phpinfo() to:
| IPv6 Support 	enabled

After a short check, this bug was introduced in 5.2.10. With 5.2.9 this is working perfect.

(That's really a pain, if you must access a IPv6 only server...)


Reproduce code:

Expected result:
A string with the content of the webpage.

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-05 16:45 UTC] carsten_sttgt at gmx dot de
It's also not working with the latest snapshot.
(Version: 5.3.1-dev; Sun, 05 Jul 2009 16:08:49 +0000)
 [2009-07-05 18:12 UTC] carsten_sttgt at gmx dot de
Same problem on OS X.
 [2009-07-05 18:17 UTC] carsten_sttgt at gmx dot de
Also not working on Linux.
 [2009-07-06 12:43 UTC]
Can you provide an url to an ipv6 only server?
 [2009-07-06 14:08 UTC] carsten_sttgt at gmx dot de
An example may be: or

(our in-house company servers are not accessible by the outside world)

But don't you think it's easier to test this with a local webserver like Apache?

It doesn't matter if this is an IPv6 only or a dual stack server. Connections with the IPv6 address doesn't work. That's the point.
 [2009-09-19 05:58 UTC]
Conveniently, I have a host name ( that only has AAAA records, which simplifies testing somewhat. It has both regular HTTP and Gopher servers -- Gopher's a particularly simple protocol to test (send a newline, get an index), so it's quite useful in this case. :)

This appears to be an issue somewhere in the streams code; I can confirm that this is still occurring with the current PHP_5_3 branch (tested on Linux). There's no dependency on whether a host name or IP address are provided; both fail the same way. It's notable that no error information is filled out, socket_stream_create() simply returns false and sets errno to 0.

A direct AF_INET6 socket connection works as expected.


HTTP wrapper:

<?php var_dump(file_get_contents('')); ?>


Warning: file_get_contents( failed to open stream: operation failed in /tmp/wrapper.php on line 1

Call Stack:
    0.0001     629088   1. {main}() /tmp/wrapper.php:0
    0.0001     629232   2. file_get_contents() /tmp/wrapper.php:1


Stream socket:

$errno = $errstr = null;
$r = stream_socket_client('tcp://[2002:cfc0:4611::1]:70/', &$errno, &$errstr);
if ($r) {
        fwrite($r, "\r\n");
        $data = '';
        while ($packet = fread($r, 16384)) {
                $data .= $packet;
else {
        echo "Error: $errno; $errstr\n";


Warning: stream_socket_client(): unable to connect to tcp://[2002:cfc0:4611::1]:70/ (Unknown error) in /tmp/stream.php on line 3

Call Stack:
    0.0002     634424   1. {main}() /tmp/stream.php:0
    0.0002     634856   2. stream_socket_client() /tmp/stream.php:3

Error: 0;

Direct socket connection:

$sock = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP) or die(socket_strerror(socket_last_error()));
socket_connect($sock, '2002:cfc0:4611::1', 70) or die(socket_strerror(socket_last_error()));
socket_write($sock, "\r\n");
$data = '';
while ($packet = socket_read($sock, 16384)) {
        $data .= $packet;


string(1230) "iFive Minutes     /     70
<normal Gopher output snipped>

I can't see anything obvious in the 5.2.9 -> 5.2.10 diff that might have caused this, but I'm hardly an expert on the streams code, so this is likely to need someone more qualified to look at it. Hopefully this helps isolate the problem somewhat -- if I can help test this further, please let me know.
 [2009-09-19 06:30 UTC]
OK, further digging suggests that the reason for the failure is in php_network_connect_socket_to_host() in main/network.c. At the moment, IPv6 connections require that the bindto context option be present for them to work. For example, this code works normally:

$ctx = stream_context_create(array('socket' => array('bindto' => '[::]:38401')));
var_dump(file_get_contents('', 0, $ctx));

This was introduced by the fix for bug #48131. A patch against PHP_5_3 at fixes this bug by effectively replicating the IPv4 codepath for IPv6, and effectively reverts revision 279841, which introduced the issue. Whether this fix is correct or not really depends on your point of view vis-a-vis bug #48131 -- I'm not actually sure bindto should be used to choose IPv4 or IPv6 anyway, but I guess it might be a valid use case.
 [2009-09-19 11:15 UTC]
Ilia, Can you take a look please? It seems that you fixed the other one.
 [2009-09-30 20:48 UTC]
Automatic comment from SVN on behalf of iliaa
Log: Fixed bug #48805 (IPv6 socket transport is not working).
 [2009-09-30 20:48 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2009-10-10 12:21 UTC]
Automatic comment from SVN on behalf of pajoye
Log: - Merge: Fixed bug #48805 (IPv6 socket transport is not working)
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 20:01:28 2024 UTC