php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63730 gethostbyname() fails silently
Submitted: 2012-12-08 23:18 UTC Modified: 2012-12-09 15:08 UTC
From: cojabo-php at cjbn dot net Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.3.19 OS: Ubuntu LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cojabo-php at cjbn dot net
New email:
PHP Version: OS:

 

 [2012-12-08 23:18 UTC] cojabo-php at cjbn dot net
Description:
------------
gethostbyname() fails to return an IP; dns_get_record() works.

No error message of any kind is generated.

This happens for any domain I've tried.

Test script:
---------------
<pre>
<?
$domain='www.example.com';

echo "gethostbyname($domain)\n";
var_dump(gethostbyname($domain));

echo "\n";

echo "dns_get_record($domain,DNS_A)\n";
var_dump(dns_get_record($domain,DNS_A));

echo $notice;
fopen('warning','r');


Expected result:
----------------
gethostbyname(www.example.com)
string() "192.0.43.10"

dns_get_record(www.example.com,DNS_A)
array(1) {
  [0]=>
  array(5) {
    ["host"]=>
    string(15) "www.example.com"
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(11) "192.0.43.10"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(3020)
  }
}

Notice: Undefined variable: notice in /www/dev/dynamic/test.php on line 14

Warning: fopen(warning): failed to open stream: No such file or directory in /www/dev/dynamic/test.php on line 15

Actual result:
--------------
gethostbyname(www.example.com)
string(15) "www.example.com"

dns_get_record(www.example.com,DNS_A)
array(1) {
  [0]=>
  array(5) {
    ["host"]=>
    string(15) "www.example.com"
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(11) "192.0.43.10"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(3020)
  }
}

Notice: Undefined variable: notice in /www/dev/dynamic/test.php on line 14

Warning: fopen(warning): failed to open stream: No such file or directory in /www/dev/dynamic/test.php on line 15

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-09 13:14 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-12-09 13:14 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

"Returns the IPv4 address or a string containing the *unmodified hostname*  on 
failure." 

http://us1.php.net/manual/en/function.gethostbyname.php
 [2012-12-09 15:08 UTC] cojabo-php at cjbn dot net
What is the reason for that failure? How do I determine this?
It seems strange that the "intended behavior" would be to fail without giving the user any 
means whatsoever to correct the failure.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 27 17:01:27 2025 UTC