Bug #73307 [Opn->Nab]: Stream Socket Server unable to create IPv4/IPv6 Sockets

From: Date: Wed, 19 Oct 2016 10:43:51 +0000
Subject: Bug #73307 [Opn->Nab]: Stream Socket Server unable to create IPv4/IPv6 Sockets
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204913@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73307&edit=1 ID: 73307 Updated by: bwoebi@php.net Reported by: lucius at luciusgaitan dot com Summary: Stream Socket Server unable to create IPv4/IPv6 Sockets -Status: Open +Status: Not a bug Type: Bug Package: Unknown/Other Function Operating System: CentOS 7.2.1511 x64 PHP Version: 7.0.11 Block user comment: N Private report: N New Comment: This is behavior of the underlying syscalls; some OS choose to map IPv4 into the IPv6 space in general. (And thus [::] is a superset of 0.0.0.0 there, leading to address already in use.) Under Linux you may find your default behavior under /proc/sys/net/ipv6/bindv6only (1 if separated, 0 if overlapping). Additionally, to explicitly control it from the script, PHP 7.0.1+ expose a "ipv6_v6only" socket stream context option. Try: $ctx = stream_context_create(['socket' => ['ipv6_v6only' => true]]); Previous Comments: ------------------------------------------------------------------------ [2016-10-12 16:45:16] lucius at luciusgaitan dot com Description: ------------ Having a dual stack server, php is unable to create two sockets in the same port for different addresses ipv4 and ipv6. Only the first attempt to create the socket succeeds, the second returns "PHP Warning: stream_socket_server(): unable to connect to ... (Address already in use)". Using the defaults 0.0.0.0 and [::]. If the real ip addresses are defined everything works well. Also, $errno equals to 0 and returned value is FALSE as described in /manual/en/function.stream-socket-server.php. ./configure --with-config-file-path=/etc --disable-short-tags --enable-bcmath --enable-calendar --enable-gd-native-ttf --enable-mbstring --enable-pdo=shared --enable-sockets --enable-zip --with-curl=/opt/curlssl/ --with-freetype-dir=/usr --with-gd --with-jpeg-dir=/usr --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-pic --with-png-dir=/usr --with-zlib --with-zlib-dir=/usr --enable-pcntl --with-bz2 -enable-opcache --enable-fpm --with-fpm-systemd Thank you. Test script: --------------- $errno = null; $error = null; $bindto = ['0.0.0.0', '[::]']; $socket = []; for ($x = 0; $x < 2; ++$x) { $ctx = stream_context_create(['socket' => ['bindto' => $bindto[$x] . ':3672']]); $socket[] = stream_socket_server('tls://' . $bindto[$x] . ':3672', $errno, $error, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $ctx); } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73307&edit=1

« previous php.bugs (#204913) next »