php.net |  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
Votes:5
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
 [2009-07-05 16:13 UTC] carsten_sttgt at gmx dot de
Description:
------------
Hallo,

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...)

Regards,
Carsten


Reproduce code:
---------------
<?php
var_dump(file_get_contents('http://[::1]/'));
?>


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

Actual result:
--------------
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] jani@php.net
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:
ipv6.google.com or ipv6.beijing2008.cn

(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?

BTW:
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] aharvey@php.net
Conveniently, I have a host name (ipv6.adamharvey.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.

Tests:

HTTP wrapper:

<?php var_dump(file_get_contents('http://ipv6.adamharvey.name/')); ?>

Output:

Warning: file_get_contents(http://ipv6.adamharvey.name/): 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

bool(false)


Stream socket:

<?php
$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;
        }
        var_dump($data);
        fclose($r);
}
else {
        echo "Error: $errno; $errstr\n";
}
?>

Output:

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:

<?php
$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;
}
var_dump($data);
?>

Output:

string(1230) "iFive Minutes     /       xn--9bi.net     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] aharvey@php.net
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:

<?php
$ctx = stream_context_create(array('socket' => array('bindto' => '[::]:38401')));
var_dump(file_get_contents('http://ipv6.adamharvey.name/', 0, $ctx));
?>

This was introduced by the fix for bug #48131. A patch against PHP_5_3 at http://www.adamharvey.name/stuff/bug48805.patch 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] pajoye@php.net
Ilia, Can you take a look please? It seems that you fixed the other one.
 [2009-09-30 20:48 UTC] svn@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=289019
Log: Fixed bug #48805 (IPv6 socket transport is not working).
 [2009-09-30 20:48 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2009-10-10 12:21 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=289498
Log: - Merge: Fixed bug #48805 (IPv6 socket transport is not working)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC