【问题标题】:PHP file_get_contents() functionPHP file_get_contents() 函数
【发布时间】:2016-02-27 12:59:33
【问题描述】:

我尝试了http://php.net/manual/en/function.file-get-contents.php的第一个示例

<?php
   $homepage = file_get_contents('http://www.scibet.com/');
   echo $homepage;
?>

我只知道:

Notice: file_get_contents(): send of 16 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2

Notice: file_get_contents(): send of 22 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2

Notice: file_get_contents(): send of 19 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2

Notice: file_get_contents(): send of 2 bytes failed with errno=10053 An established connection was aborted by the software in your host machine. in C:\xampp\htdocs\scraper\test.php on line 2

Warning: file_get_contents(http://www.scibet.com/): failed to open stream: HTTP request failed! in C:\xampp\htdocs\scraper\test.php on line 2

问题出在哪里?

【问题讨论】:

标签: php mysql apache web-scraping file-get-contents


【解决方案1】:

您的设置可能未设置allow_url_fopen。您需要设置配置指令才能通过 HTTP 打开文件,因为默认情况下 file_get_contents() 仅适用于本地文件。

有关如何执行此操作的更多说明,请参见此处: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

【讨论】:

  • 在 php.ini 中是 allow_url_fopen = on
  • file_get_contents() only works for local files 不正确。
  • @FakhruddinUjjainwala 来自 PHP 文档:如果启用了 fopen 包装器,则 URL 可以用作此函数的文件名。 默认情况下它们被禁用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-04
  • 2017-09-14
相关资源
最近更新 更多