PHP imap_open通过Apache失败,带有;“没有这样的主人”;但它在命令行工作

PHP imap_open通过Apache失败,带有;“没有这样的主人”;但它在命令行工作,php,email,Php,Email,我在CentOS 5.8上使用PHP5.3.10。PHP是使用以下配置从源代码构建的: ./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 \ --wit

我在CentOS 5.8上使用PHP5.3.10。PHP是使用以下配置从源代码构建的:

./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
我确信系统上没有其他版本的PHP,并且我已经通过浏览器和CLI确认imap扩展可用

这个问题影响了我正在使用的CMS,但为了测试,我使用了一个简单的PHP脚本,它是:

<?php
error_reporting(15);

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

$mailserver = "{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX";

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

$headers = imap_headers($link);
print_r($headers);
?>
然后在imap_头失败时发出附加警告

显然,imap扩展可以通过Apache和CLI获得,这不应该是防火墙或DNS问题,因为它确实可以通过CLI工作。我还可以远程登录邮件服务器

我使用的是默认的php.ini-development文件(副本为),并通过phpinfo()和php-I确认这两种环境都在使用它

有人知道为什么imap_open会通过Apache而不是命令行返回“没有这样的主机…”吗

编辑:


我正在使用股票centos yum repos中的libc-client和libc-client-devel版本2004g-2.2.1和httpd 2.2.3-63.el5.centos.1。我忘记了Apache使用的是mod_chroot,显然访问提供DNS的库被阻止了。我不得不将
LoadFile/lib64/libnss\u dns.so.2
添加到我的httpd.conf,这要感谢。

我遇到了fqdn无法解决的问题,所以我将其添加到本地主机,或者修复了我的dns,并且它可以从CLI而不是通过apache工作。但是重新启动apache后,一切正常,所以尝试重新启动,看看它是否解决了问题。Mike,我认为你的思路是对的。对gethostbyaddr('pop.gmail.com')的调用通过CLI工作,并通过浏览器失败。不过,重启Apache并没有帮助。我还重新启动了nscd。哦,不。。我忘了Apache正在使用mod_chroot,这将阻止DNS查找。这里有一个解决方法,一旦它起作用,我会发布它。另外,请检查您是否启用了SELinux。它可能也阻止了httpd访问。我不得不将LoadFile/lib64/libnss_dns.so.2添加到我的httpd.conf中,解决了这个问题。不幸的是,mod_chroot现在正在干扰请求的SSL部分,但这是另一个问题。迈克,谢谢你给我指DNS。
Warning: imap_open() [function.imap-open]: Couldn't open stream {pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX in test.php on line 9
Array ( [0] => No such host as pop.gmail.com )