PHP imap_open fails via Apache with “no such host” but works at command line

I am using PHP 5.3.10 on CentOS 5.8. PHP has been built from source with this config:

./configure --enable-gd-native-ttf --enable-mbstring \
  --enable-sockets --with-bz2 --with-curl --with-gd --with-mcrypt \
  --with-mysql --with-mhash --with-mysqli --with-openssl --with-pdo-mysql \
  --with-pear --with-pcre-regex --with-xsl --with-zlib --with-libdir=/lib64 \
  --with-imap --with-kerberos --with-imap-ssl --with-apxs2=/usr/sbin/apxs

I am positive there are no other versions of PHP on the system, and I've confirmed that through the browser and CLI that the imap extension is available.

This issue is affecting a CMS I'm using, but to test I used a simple PHP script, which is:


$username = "username";
$password = "password";

$mailserver = "{}INBOX";

$link = imap_open($mailserver, $username, $password, NULL, 1);

$headers = imap_headers($link);

When I run this at the command line I get the expected output which is no error messages and a list of the messages in the inbox.

When I point a browser to the test script I get:

Warning: imap_open() [function.imap-open]: Couldn't open stream {}INBOX in test.php on line 9
Array ( [0] => No such host as ) 

and then additional warnings as imap_headers fails.

Clearly the imap extension is available via Apache and CLI, and this shouldn't be a firewall or DNS issue as it does work from the CLI. I can also telnet to the mail server.

I am using the default php.ini-development file (a copy is here) and confirmed with phpinfo() and php -i that it's in use by both environments.

Does anyone have any ideas why imap_open would come back with "no such host as..." through Apache but not at the command line?


I am using libc-client and libc-client-devel version 2004g-2.2.1 and httpd 2.2.3-63.el5.centos.1 from the stock CentOS yum repos


I forgot that Apache was using mod_chroot and apparently access to the library providing DNS was blocked. I had to add LoadFile /lib64/ to my httpd.conf, thanks to this page.

Need Your Help

WCF security implementation for multiple platforms on mobile devices

c# wcf security rest mobile

We currently have a whole bunch of WCF REST services that are exposed to the internet. Multiple mobile devices consume these services (iOS, Android, Symbian, etc.) as well as an array of cross-plat...

How do I convert base64-encoded text to hexadecimal in VB.NET?

.net hex base64

I have come across some Base64 conversion functions in .net(FromBase64.string etc). What i want is, for a sample, i have a base 64 encoded string as

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.