ID: 48805 Updated by: il...@php.net Reported By: carsten_sttgt at gmx dot de -Status: Assigned +Status: Closed Bug Type: Streams related Operating System: * PHP Version: 5.*, 6 (2009-07-06) Assigned To: iliaa New Comment:
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. Previous Comments: ------------------------------------------------------------------------ [2009-09-30 20:48:41] s...@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-19 11:15:51] paj...@php.net Ilia, Can you take a look please? It seems that you fixed the other one. ------------------------------------------------------------------------ [2009-09-19 06:30:56] ahar...@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 05:58:51] ahar...@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-07-06 14:08:48] 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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/48805 -- Edit this bug report at http://bugs.php.net/?id=48805&edit=1