【问题标题】:file_get_contents failed to open stream: Connection refused godaddy server with remote connection server [closed]file_get_contents 无法打开流:连接拒绝 Godaddy 服务器与远程连接服务器 [关闭]
【发布时间】:2015-04-11 14:09:36
【问题描述】:

我们的 url 是远程 url。我可以通过 IP 地址运行。它抛出错误为“file_get_contents 无法打开流:连接被拒绝”。我已经使用了这个代码。

代码:

$html = file_get_contents('http://xx.xxx.xx.xx:xxxx/apps/index.php');
print_r($html);
var_dump($html); 

这是什么错误?

【问题讨论】:

  • 它可以在本地和任何电脑上工作,但它不能在 Godaddy 服务器上工作
  • @Lorenz Meyer,我没明白这一点。
  • 但我已经连接到远程服务器 url 然后错误显示 file_get_contents 无法打开流:连接被拒绝

标签: php sql-server remote-server phpinfo


【解决方案1】:

出于安全原因,许多主机会阻止您从远程 URL 加载文件(php.ini 中的allow_url_fopen 设置)。最好使用 CURL 来下载文件的内容。

<?php
$url = 'http://xx.xxx.xx.xx:xxxx/apps/index.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

参考:Get file content via PHP cURL

HTH :)

【讨论】:

  • 当我使用此代码时,它返回空白页。它没有显示任何错误。
【解决方案2】:

获取页面需要您打开流。 像这样的:

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>

参考请查看PHP.net:http://php.net/manual/en/function.file-get-contents.php

【讨论】:

  • file_get_contents():打开流失败:没有这样的文件或目录错误触发
猜你喜欢
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
相关资源
最近更新 更多