View previous topic :: View next topic |
Author |
Message |
nautical9 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/9599277003e596c6b1c68e.jpg)
Joined: 24 Feb 2003 Posts: 22 Location: Calgary, Alberta, Canada
|
Posted: Fri Mar 18, 2005 11:05 am Post subject: php dns not working (gethostbyname) |
|
|
Got a PHP DNS-related problem that I can't figure out:
For some reason, my Apache 2.0.52 / PHP 5.0.3 install doesn't want to let me do DNS lookups in the php code, at least not in the traditional way, but it's also not giving me any hints whatsoever in the log files. It just fails (very quickly).
But here's the kicker: some of the newer DNS functions are working (and of course, DNS is working everywhere else on the machine).
Here's a quick breakdown:- curl_exec - always returns "Couldn't resolve host"
- gethostbyname ('bugs.php.net') - always returns the hostname I pass to it (meaning it's failed according to the docs).
But these work:- checkdnsrr ('bugs.php.net') - returns 1 (true - meaning it found a record).
- dns_get_record('bugs.php.net',DNS_ANY) - returns an array with all the proper DNS info.
I really need to use the "curl" library for grabbing some HTTPS pages remotely, or else I'd just use the newer DNS functions. But every hostname I try to fetch with the curl libraries fails (but 'curl' on the command line works fine). I could probably work around it with a nasty "exec" call to "curl", but I'd really rather avoid that.
I've also spent over an hour trying to track down others who have had this problem elsewhere on the Net, to no avail.
Any helpful pointers would be greatly appreciated.
-D. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
ydleiF Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/1089377100406230c81a0fb.jpg)
Joined: 15 Nov 2002 Posts: 170 Location: Southeast Michigan, USA
|
Posted: Mon Mar 21, 2005 4:55 pm Post subject: |
|
|
Looking at the possible USE flags for 5.0.3, I'd just make sure you have curl and possibly sockets enabled. Other than that, I'm not very sure. Check out the other USE flags as well, it might be one of those. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
nautical9 n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/9599277003e596c6b1c68e.jpg)
Joined: 24 Feb 2003 Posts: 22 Location: Calgary, Alberta, Canada
|
Posted: Fri Mar 25, 2005 11:00 am Post subject: Still stumped, but here's a quick workaround |
|
|
curl_exec() and gethostbyname() still can't seem to resolve DNS addresses for me, and I've given up trying to figure out how to properly fix it (thx for the advice re: USE flags, but I already have both set).
In case other people have this problem (and dns_get_record() is working), a simple workaround is:
Code: |
// First get IP address of the hostname
$dns = dns_get_record ('www.example.com', DNS_A);
// Make sure it worked
if (! isset ($dns[0]['ip'])) {
// error - no results for DNS lookup
}
// Build the URL using the IP address
$url = "http://" . $dns[0]['ip] . "/path/to/whatever.html";
// Use curl to get the remote page
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$results = curl_exec ($ch);
// Make sure we got a page
if (curl_errno ($ch) || ! $results) {
// error - display with curl_error ($ch)
}
// Page is in $results
echo "$results";
|
Not as clean as just requesting the full path in one line, but at least it works without hard-coding an IP address. Also for HTTPS connections, make sure to curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0), since the common-name of the cert won't match the IP address. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|