Bug #80067 [Opn->Fbk]: Omitting the port in bindto setting results in "Failed to parse address" error
| From: | requinix@php.net | Date: | Sun, 06 Sep 2020 21:20:02 +0000 |
| Subject: | Bug #80067 [Opn->Fbk]: Omitting the port in bindto setting results in "Failed to parse address" error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228903@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80067&edit=1
ID: 80067
Updated by: requinix@php.net
Reported by: me at derrabus dot de
Summary: Omitting the port in bindto setting results in
"Failed to parse address" error
-Status: Open
+Status: Feedback
Type: Bug
Package: Sockets related
Operating System: macOS 10.15
PHP Version: 7.4.10
Block user comment: N
Private report: N
New Comment:
The documentation doesn't actually say that "0" is allowed.
https://www.php.net/manual/en/context.socket.php
> Used to specify the IP address (either IPv4 or IPv6) and/or the port number that
> PHP will use to access the network. The syntax is ip:port for IPv4 addresses,
> and [ip]:port for IPv6 addresses. Setting the IP or the port to 0 will let the
> system choose the IP and/or port.
Thus the allowed values are "0:0" and ":0".
Previous Comments:
------------------------------------------------------------------------
[2020-09-06 21:17:00] me at derrabus dot de
Description:
------------
Before php 7.4.10, it was possible to provide a "bindto" setting without a port via the
socket stream context. With 7.4.10, a warning is raised and the stream is not opened.
This breaks Symfony's HttpClient component, see https://github.com/symfony/symfony/issues/38081
for details.
The attached test script reproduces the regression. Executing it on php 7.4.9 produces the expected
result. On php 7.4.10, the script fails. If you change the "bindto" setting to
"0:0", the script passes on both versions, 7.4.9 and 7.4.10.
Test script:
---------------
<?php
$context = stream_context_create(['socket' => ['bindto' =>
'0']]);
var_dump(file_get_contents('https://httpbin.org/get', false, $context));
Expected result:
----------------
string(200) "{
"args": {},
"headers": {
"Host": "httpbin.org"
},
"origin": "1.2.3.4",
"url": "https://httpbin.org/get"
}
Actual result:
--------------
Warning: file_get_contents(https://httpbin.org/get): failed to open stream: Failed to parse address
"0" in /app/test.php on line 4
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80067&edit=1