Skip to content

Socket options: bindto => 0:0 throwing Invalid IP address 0 #12190

Closed
@remizyaka

Description

@remizyaka

Description

It is not possible to bint to ip4 address using context options any more. In documentation:

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

but in fact it is not allow us to put 0 for ip address.

The following code:

<?php
$url = 'https://google.com';
$ctx  = stream_context_create([
                    'socket' => [
                        'bindto'=>'0:0'
                    ],
                    'http' =>
                        [
                            'timeout' => 10,
                        ],
                ]);
                $feed = file_get_contents($url, false, $ctx);

Resulted in this output:

file_get_contents(): Invalid IP Address: 0

But I expected this output instead:

actual content of google page

PHP Version

PHP 8.2.5

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions