Skip to content

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

Closed

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

Activity

  1. devnexen commented on Sep 12, 2023

    @devnexen
    Member

    The script works with PHP 7.4 for example indeed. One of the key differences is the priorisation of the inet_pton's usage above inet_aton in >= PHP 8.1

  2. self-assigned this
    on Sep 12, 2023
  3. added a commit that references this issue on Sep 24, 2023
    d65c800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions