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

时间:2012-05-02 19:13:39

标签: php email

我在CentOS 5.8上使用PHP 5.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);
?>

当我在命令行运行时,我得到预期的输出,这是没有错误消息和收件箱中的消息列表。

当我将浏览器指向测试脚本时,我得到:

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 ) 

然后在imap_headers失败时发出其他警告。

显然,imap扩展可以通过Apache和CLI获得,这不应该是防火墙或DNS问题,因为它可以在CLI中运行。我也可以telnet到邮件服务器。

我正在使用默认的php.ini-development文件(副本为here)并通过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

1 个答案:

答案 0 :(得分:0)

我忘了Apache正在使用mod_chroot并且显然访问了提供DNS被阻止的库。由于this page,我不得不将LoadFile /lib64/libnss_dns.so.2添加到我的httpd.conf中。

相关问题