gpt4 book ai didi

php - Yii curl Couldn't resolve host 错误 CentOs 6

转载 作者:太空宇宙 更新时间:2023-11-03 17:16:41 25 4
gpt4 key购买 nike

我遇到了错误 “无法解析主机 '...'” 的麻烦。我还研究了许多主题,但找不到解决方法。

第一次,同样的代码,我可以毫无问题地执行curl。但是今天它突然停止工作了。这是我的尝试

  1. 与我的本地主机中的代码相同,curl 工作正常。
  2. 在我的服务器 CentOs 6(使用 Cpanel Whm)中,我的目录结构如下所示

    • public_html
    • -YiiWebsiteFolder
    • -curl_test.php

我可以在 curl_test.php 中对相同的 URL 运行 curl 而没有问题,它工作正常。即使我将 curl_test.php 放在 YiiWebsiteFolder 中,它也能正常工作,所以问题不在于权限。

但是如果我运行相同的代码通过 Yii (YiiWebsiteFolder) 调用 curl,在 Yii Controller 和操作中运行它,它会引发错误 'Couldn “解析主机...”。(我的 URL 重写很正常,我的网站 URL 看起来像 "mydomain.com/index.php/test/myaction")

所以我猜原因可能是Yii,而不是DNS problem就像一些帮助主题所说的那样。

http://forums.cpanel.net/f34/file_get_contents-couldnt-resolve-host-name-120065.html

Couldn't resolve host and DNS Resolution failed

本地机器和服务器的 Yii 配置 main.php 文件是一样的。

已编辑:我找到了这个和我有同样问题的人

cURL doesn't work when it's used in a PHP application and running > through a web browser

cURL doesn't work when it's used in a PHP application and running through a web browser. However, that same PHP page with cURL, when run via the terminal, does what it's supposed to do and fetches the information that I want

但他发现问题出在 DAEMON 数组上,但我没有使用 Apache DAEMON(甚至我也不确定它是什么)。

我已经尝试了所有可能的解决方案,例如重新启动我的网络和我的 apache 以更改它们启动时的顺序,修改 etc/resolv.conf/(添加或删除 12.0.0.1 并尝试一些公共(public) DNS)

service network stop

service network start

service network restart

/sbin/service httpd stop

/sbin/service httpd start

我花了很多时间来解决这个问题,但根本没有成功。非常感谢任何帮助。

最佳答案

这并没有解决您的具体问题,但我想我应该发帖说我遇到了同样的问题,即当 PHP 脚本从 Web 浏览器运行时,PHP cURL 无法解析任何主机名,但相同的脚本从终端命令行工作正常(即 cURL 解析主机名以返回预期的响应)。就我而言,它是通过以下方式解决的:

/sbin/service httpd 停止

/sbin/service httpd 启动

关于php - Yii curl Couldn't resolve host 错误 CentOs 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18901827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com