PHP include() 通过 HTTP 导致 Apache 超时

PHP include() 通过 HTTP 导致 Apache 超时

从旧服务器移至在 CentOS6.4 上运行的 WHM/cPanel 后,我遇到了 ExpressionEngine2 问题。简单的测试代码可重现该问题:

<?php 
        $protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === FALSE ? 'http' : 'https';
        $host = $_SERVER['HTTP_HOST'];
        include($protocol . '://' . $host . '/header.html'); 
?>
    <p> Main text...</p>
<?php
        include($protocol . '://' . $host . '/footer.html'); 
?>

header.html 的样子

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

并且 footer.html 如下所示:

</body>
</html>

创建 Apache 超时:

Warning: include(http://www.domain.com/header.html) [function.include]: failed to open stream: Connection timed out in /home/domain/public_html/test/index.php on line 5

Warning: include() [function.include]: Failed opening 'http://www.domain.com/header.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/domain/public_html/test/index.php on line 5

Main text...

Warning: include(http://www.domain.com/footer.html) [function.include]: failed to open stream: Connection timed out in /home/domain/public_html/test/index.php on line 12

Warning: include() [function.include]: Failed opening 'http://www.domain.com/footer.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/domain/public_html/test/index.php on line 12

有任何线索表明 Apache 或 PHP 配置可能出了什么问题吗?

谢谢

答案1

可能什么都没有。错误消息说明了一切:

Warning: include(http://www.domain.com/footer.html) [function.include]: failed to open stream: Connection timed out in /home/domain/public_html/test/index.php on line 12

远程包含的站点连接超时。这是某种连接问题;可能是防火墙或路由问题(如果没有关于您的环境的信息,特别是两个服务器相互之间的关系,就无法判断)。

如果出于某种原因,您使用远程包含来访问同一服务器上的文件(为什么要这样做),请尝试使用该服务器上的浏览器查询自身。如果不能,则可能是 apache 没有监听环回接口,但您的新hosts文件导致域名解析为127.0.0.1

相关内容