简体   繁体   中英

file_get_contents strange issue

I'm using simple_html_dom ( http://simplehtmldom.sourceforge.net ) to parse html code. 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). I tracked the problem to this line of the library : $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');

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

returns bool(false) which means incorrect file

everything works thing on my WAMP server, but on my debian Apache server, i get that. 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)

Thanks for your help!

EDIT: I tried to add 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/******* could it be because of URL rewriting or something ? (even if it worked on local server x) )

Depends on the PHP version you are using, test the following code and see which of the statements works.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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