hostname nor servname provided, or not known

noescom2

Verified User
Joined
Oct 5, 2007
Messages
10
I have the weirdest problem on a FreeBSD 6.2 box using the latest apache and php versions. Whenever i call a socket function such as fsockopen() i see error messages. Also i can't connect to the mailbox through squirrelmail. The messages are:

Code:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in ... on line 2
fsockopen() [function.fsockopen]: unable to connect to http://www.cnn.com:80 in ... on line 2

These messages to me suggests that something goes wrong while resolving either the hostname (which is atlanta.globalwebhosting.nl) or a remote host. However, i can resolve the hostname and any other host just fine on the commandline.

I checked the contents of /etc/hosts, /etc/resolv.conf, httpd.conf and php.ini. Contents seems fine.
allow_url_fopen is ON in php.ini
I recompiled apache, php and zend.
I checked whether DNS is correctly configured via http://www.sidn.nl
I disabled the firewall.

Code:
[B]resolv.conf[/B]
lookup file bind
nameserver 85.17.96.69

Code:
[B]Hosts[/B]
127.0.0.1               localhost localhost.my.domain
85.17.42.165            atlanta.globalwebhosting.nl

Problem remains. Any suggestions?
 
I found out some new things about this problem. It seems to be an apache configuration error, but i'm not sure what is.

Code:
<?php
  echo gethostbyname("cnn.com");
?>

Code above returns an IP on the cli and returns the hostname in apache. Ergo, it's not resolving the name.

Code:
<?php
  fopen("http://<some_ip>", "r");
?>

Opens the link on the cli and times out in apache. So it's not connecting to the ip.
 
I solved this bug. I'm not sure which of the fixes i'll provide below actually solved the problem, but in the end it works again and that's what counts. Many thanks to John (DirectAdmin) and the folks of #freebsdhelp on efnet (irc) for helping out.

Fix 1:
Disable ipv6. The idea is that apache tries to resolve ipv6 addresses and fails. Disabling ipv6 prevents this.

Code:
[B]vi /etc/rc.conf[/B]
ipv6_enable="NO"

[B]vi /etc/hosts[/B]
#::1 localhost localhost.my.domain

Fix 2:
Increase max open file descriptors. How to do this is explained on http://help.directadmin.com/item.php?id=9.

Fix 3:
Reinstall perl and upgrade all packages (CPAN). I'm not sure why this helped to solve the problem. I assume there was some problem with some perl package that is used by apache, if such a thing even exists.
 
The problem returned after some while. Turns out it really was the amount of used file descriptors after all, because the problem returned when i turned CustomLog back on. Now a new problem arises:

When i disable CustomLog, webalizer has no data to generate statistics

Now, by accident I discovered that Apache 1 doesn't have this problem. I can turn on CustomLog and ErrorLog on hundreds of domains and it just works. No problems whatsoever. This seems very illogical to me. Anyone has any clues why Apache 1 has no problem opening lots of file descriptors while Apache 2 has?
 
i'm having the same problem does anyone knows an solution

i reinstalled all ports

all perl modules

apache php & mod_perl

so what can be the problem?
 
I treid a lot of things to change, but it seems that system reboot is the one that helped to get rid of this problem.
 
Back
Top