|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48131 stream_context_create / bindto not working with IPv4 on a dual IPv4/IPv6 system
Submitted: 2009-05-02 13:30 UTC Modified: 2009-05-04 14:46 UTC
From: dvasseur at diway dot net Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.*, 6CVS (2009-05-02) OS: Linux - Ubuntu 8.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
43 - 1 = ?
Subscribe to this entry?

 [2009-05-02 13:30 UTC] dvasseur at diway dot net
My system has 2 ip addresses, one ipv4 (A.B.C.D) and the other ipv6 (1:2:3:4:5:6)

I'm trying to open a file over HTTP (http://other.server/my.file.dat), 'other.server' is resolving both on ipv4 and ipv6 too.

I'd like to choose wether IPv4 or IPv6 to open the file so I'm using stream_context_create() with the 'bindto' option.

'bindto' with an ipv4 address is NOT working
'bindto' with an ipv6 address is working

Reproduce code:
The following code is working (ipv6 is used)
$opts = array(
  'socket' => array(
      'bindto' => '[1:2:3:4:5:6]:0',

$context = stream_context_create($opts);

$contents = file_get_contents('http://other.server/my.file.dat', FALSE, $context);

The following code is NOT working:
$opts = array(
  'socket' => array(
      'bindto' => 'A.B.C.D:0',

$context = stream_context_create($opts);

$contents = file_get_contents('http://other.server/my.file.dat', FALSE, $context);

=> PHP Warning:  file_get_contents(): Invalid IP Address: A.B.C.D 

Expected result:
ipv4 working

Actual result:
ipv4 NOT working


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-02 19:30 UTC] dvasseur at diway dot net
Same bug with CVS snapshot
PHP 5.2.10-dev (cli) (built: May  2 2009 21:22:25) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
 [2009-05-04 14:46 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 07:01:28 2024 UTC