【问题标题】:PHP file_get_contents() problemPHP file_get_contents() 问题
【发布时间】:2011-10-13 23:20:46
【问题描述】:

我尝试在 PHP 中使用带有 file_get_contents() 的 API 发送短信。

例如。

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");

在本地机器上运行良好。

如果我把它放到服务器 [SERVER A] 中它不起作用。如果我更改代码 IE。 file_get_contents("http://google.com"); 在服务器和本地都可以正常工作。

如果我把这个页面 ie

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");

在另一个服务器[SERVER B] 上它工作正常。

如果我的 [SERVER A] 有任何问题,那么它是如何打开 google 的?

谁能帮我解决这个问题?

【问题讨论】:

  • 不确定,但您的托管服务器可能已配置为阻止对某些网站组的请求。
  • http 获取请求...所以暴露用户名和密码不是问题吗?
  • 您在服务器 A 上是否遇到任何错误?

标签: php


【解决方案1】:

检查您的错误日志。如果file_get_contents 失败,如果您记录警告和通知,它会在 PHP 错误日志中告诉您原因。

在相关问题Why doesn't file_get_contents work? 中,有些人创建了a collaborative wiki answer that deals with how to trouble-shoot file_get_contents in detail。或许 infos 和 cmets 也能帮到你。

【讨论】:

    【解决方案2】:

    检查http://testsmssite 是否可以从服务器 A 访问(尝试 ping 它)。也许您必须将其添加到 /etc/hosts。或者,也许您必须更改 testmssite 上的设置。 IMO 这是网络问题,与 PHP 本身无关(因为在服务器 A PHP 能够从 http://google.com 加载数据)

    【讨论】:

      【解决方案3】:

      您能否检查allow_url_fopen 是否为真/启用,以获得更多http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen?这可能是一个原因。是的,Curl 可能是更好的选择。

      【讨论】:

        【解决方案4】:

        不要使用file_get_contents,而是尝试使用curl。查看您收到的回复并查看curl_error。导致请求失败的原因有很多。

        【讨论】:

          猜你喜欢
          • 2011-07-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-18
          • 2011-09-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多