简体   繁体   English

file_get_contents奇怪的问题

[英]file_get_contents strange issue

I'm using simple_html_dom ( http://simplehtmldom.sourceforge.net ) to parse html code. 我正在使用simple_html_dom( http://simplehtmldom.sourceforge.net )解析html代码。 I've built an application on my local WAMP server, and when everything worked fine, i uploaded it on my internet site, but something was crashing my server (same code as local). 我已经在本地WAMP服务器上构建了一个应用程序,当一切正常后,我将其上传到了Internet站点,但是服务器崩溃了(与本地代码相同)。 I tracked the problem to this line of the library : $contents = file_get_contents($url, $use_include_path, $context, $offset); 我将问题跟踪到库的这一行: $contents = file_get_contents($url, $use_include_path, $context, $offset);

i tried to make a test file : 我试图做一个测试文件:

<?php
$content=file_get_contents('http://mysite.net');
var_dump($content);
?>

this works fine, however $content=file_get_contents('http://mysite.net/gaming/search.php?search_id=active_topics'); 这工作正常,但是$content=file_get_contents('http://mysite.net/gaming/search.php?search_id=active_topics');

or simply $content=file_get_contents('http://mysite.net/gaming'); 或者只是$content=file_get_contents('http://mysite.net/gaming');

returns bool(false) which means incorrect file 返回bool(false) ,表示文件不正确

everything works thing on my WAMP server, but on my debian Apache server, i get that. 一切都可以在WAMP服务器上正常运行,但是在我的debian Apache服务器上,我明白了。 I thought that maybe my problem comes from my php.ini files, but i don't know where to start (both allow_url_fopen are ON) 我以为可能是我的问题来自我的php.ini文件,但我不知道从哪里开始(allow_url_fopen都为ON)

Thanks for your help! 谢谢你的帮助!

EDIT: I tried to add ini_set('display_errors',1); 编辑:我试图添加ini_set('display_errors',1); and now i get that : Warning: file_get_contents(http://mysite.net/gaming): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /web/******* 现在我明白了: Warning: file_get_contents(http://mysite.net/gaming): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /web/******* Warning: file_get_contents(http://mysite.net/gaming): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /web/******* could it be because of URL rewriting or something ? Warning: file_get_contents(http://mysite.net/gaming): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /web/*******是由于URL重写还是其他原因? (even if it worked on local server x) ) (即使它在本地服务器x上也可以工作)

Depends on the PHP version you are using, test the following code and see which of the statements works. 取决于您使用的PHP版本,测试以下代码并查看哪个语句有效。

<?php
// <= PHP 5
$file = file_get_contents('./people.txt', true);
// > PHP 5
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM