簡體   English   中英

file_get_contents奇怪的問題

[英]file_get_contents strange issue

我正在使用simple_html_dom( http://simplehtmldom.sourceforge.net )解析html代碼。 我已經在本地WAMP服務器上構建了一個應用程序,當一切正常后,我將其上傳到了Internet站點,但是服務器崩潰了(與本地代碼相同)。 我將問題跟蹤到庫的這一行: $contents = file_get_contents($url, $use_include_path, $context, $offset);

我試圖做一個測試文件:

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

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

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

返回bool(false) ,表示文件不正確

一切都可以在WAMP服務器上正常運行,但是在我的debian Apache服務器上,我明白了。 我以為可能是我的問題來自我的php.ini文件,但我不知道從哪里開始(allow_url_fopen都為ON)

謝謝你的幫助!

編輯:我試圖添加ini_set('display_errors',1); 現在我明白了: 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/*******是由於URL重寫還是其他原因? (即使它在本地服務器x上也可以工作)

取決於您使用的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