|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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.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.