php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50214 IPv6 with fsockopen broken
Submitted: 2009-11-18 10:08 UTC Modified: 2009-11-19 13:29 UTC
Votes:7
Avg. Score:4.9 ± 0.3
Reproduced:6 of 6 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: phil at lavin dot me dot uk Assigned:
Status: Closed Package: Streams related
PHP Version: 5.2.11 OS: Linux 2.6.30
Private report: No CVE-ID: None
 [2009-11-18 10:08 UTC] phil at lavin dot me dot uk
Description:
------------
When connecting to an IPv6 address, either hostname or raw address in [] an 'unknown error' is thrown. This problem occurs on both Linux and BSD and both test machines can correctly telnet to the requested address.

phil@127dot0dot0dot1:~$ php info.php | grep -i ipv6
IPv6 Support => enabled
phil@127dot0dot0dot1:~$

Reproduce code:
---------------
<?php
$a = fsockopen('[2610:1e8:2900:a::8]', 6667);

if ($a) { echo 'yay'; } else { echo 'nay'; }
?>


Expected result:
----------------
The code should echo 'yay'.

Actual result:
--------------
Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Unknown error) in /root/test.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-18 14:28 UTC] jani@php.net
Was PHP compiled properly? ie. did you enable ipv6 support? (check phpinfo() output for 'IPv6 Support'.
 [2009-11-18 14:37 UTC] phil at lavin dot me dot uk
The grep output in the original bug report is of a phpinfo. It is 'enabled'

Phil
 [2009-11-18 16:53 UTC] jani@php.net
# sapi/cli/php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'

Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Network is unreachable) 

..so I'd say your system is either misconfigured or missing ipv6 support or the target is not there. :)
 [2009-11-18 16:55 UTC] phil at lavin dot me dot uk
My system is fine. It has IPv6 support and the target is there.

phil@127dot0dot0dot1:~$ telnet 2610:1e8:2900:a::8 6667
Trying 2610:1e8:2900:a::8...
Connected to 2610:1e8:2900:a::8.
Escape character is '^]'.
:Equinox.GeekShed.net NOTICE AUTH :*** Looking up your hostname...
:Equinox.GeekShed.net NOTICE AUTH :*** Found your hostname
^]
telnet> close
Connection closed.
phil@127dot0dot0dot1:~$

I have had this same issue on both a Linux box and a BSD box running 5.2.11

Phil
 [2009-11-18 16:58 UTC] phil at lavin dot me dot uk
I have just tested it on 5 different servers running 5.2.11. All give the same error, e.g.

phil@server:~$ php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'

Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Unknown error) in Command line code on line 1
bool(false)
You have new mail in /var/mail/phil
phil@server:~$

This is regardless of whether they do or don't have IPv6 support.

A server running 5.2.9 gives what you got:

phil@server1:~$ php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'

Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Network is unreachable) in Command line code on line 1
bool(false)
phil@server1:~$

Phil
 [2009-11-18 17:00 UTC] jani@php.net
When compiled properly 5.2.11 will give what I got. 
 [2009-11-18 17:05 UTC] phil at lavin dot me dot uk
Can you please define 'properly' so that I may contact the package maintainers of PHP for Debian, FreeBSD and RHEL to notify them that they are doing something wrong.

I would have thought that, considering phpinfo reports that IPv6 is enabled in the php compile on every server, it should work correctly.
 [2009-11-18 18:03 UTC] jani@php.net
It's properly configured if it's not disabled in configure line with --disable-ipv6 option. f.e.:

# rm -f config.cache && ./configure && make
# sapi/cli/php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'
Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Network is unreachable)..

 [2009-11-18 19:02 UTC] phil at lavin dot me dot uk
Having just downloaded and compiled 5.2.11 (just using ./configure with no options)...

phil@127dot0dot0dot1:~/php5/php-5.2.11$ sapi/cli/php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'

Warning: fsockopen(): unable to connect to [2610:1e8:2900:a::8]:6667 (Unknown error) in Command line code on line 1
bool(false)
phil@127dot0dot0dot1:~/php5/php-5.2.11$


Phil
 [2009-11-18 22:24 UTC] carsten_sttgt at gmx dot de
The same problem exists with 5.2.11 on Windows too.

Of course that's a known problem, and exists also in PHP 5.3.0. In PHP 5.3.1 (rc/dev) that's fixed.

Is (/was) there no backport to 5.2.11?

Regards,
Carsten
 [2009-11-19 08:39 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-11-19 11:54 UTC] phil at lavin dot me dot uk
phil@127dot0dot0dot1:~/php5/php5.2-200911190930$ sapi/cli/php -r 'var_dump(fsockopen("[2610:1e8:2900:a::8]", 6667));'
resource(4) of type (stream)
phil@127dot0dot0dot1:~/php5/php5.2-200911190930$

I assume this fix will be pushed out in 5.2.12?

Phil
 [2009-11-19 13:29 UTC] iliaa@php.net
This bug has been fixed in SVN.

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

The fix is already in and will be part of 5.2.12
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 00:01:29 2024 UTC