2016-02-05 36 views
0

我刮http://www.beautyinzone.net/特定的URL。無法加載與file_get_contents()函數

我使用簡單file_get_contents()加載此URL。

它在我的本地主機上完美工作。但是,當我在我的實時服務器上傳時,它不起作用。

Warning: file_get_contents(http://www.beautyinzone.net/): failed to open stream: Connection timed out in script.php on line 36 page 

如果我打開一些其他的URL,它工作正常。

URL

我與捲曲嘗試很好,但顯示空白頁,什麼都不返回。

一個想法來到我的腦海裏,也許我阻止,但它不應該是這樣的,上述網站使用我的服務器。

什麼樣的問題可以阻止我加載該URL?

+2

的file_get_contents對我的作品 – felipsmartins

+0

[捲曲對我的作品(https://開頭requestable.pieterhordijk.com/xVd7o) – PeeHaa

+0

是的,它在localhost上也是這樣......但是請看..我把刮板放在我的服務器上......它不會刮擦http://www.coszi.com/crawl/beautyinzone .php – Umair

回答

0

試試這個片斷捲曲

function retrieve_curl_info() { 
    $ch = curl_init(); 
    curl_setopt_array($ch, array(
     CURLOPT_URL => 'http://www.beautyinzone.net/', 
     CURLOPT_RETURNTRANSFER => true 
    )); 
    $output = curl_exec($ch); 
    curl_close($ch); 
    return $output 
} 

此外,檢查出這個thread

0

它爲我工作。 嘗試通過下面的代碼

if (!$content = file_get_contents("http://www.beautyinzone.net/")) { 
    $error = error_get_last(); 
    echo $error['message']; 
} else { 
    echo "working fine"; 
} 
1

得到錯誤,因爲遠程服務器延遲迴復你重新獲得一個http超時錯誤。這很正常。

TCP套接字有超時設置,並在達到此超時時引發超時錯誤。一般情況下,超時時間爲30秒(默認情況下使用default_socket_timeoutphp.ini設置)。

也許你想設置(增加)的自定義超時自己:

<?php 

$http_context = stream_context_create(array(
    'http' => array(
     'timeout' => 60.0 # 60 seconds 
    ) 
)); 
$url = 'http://www.beautyinzone.net'; 
$content = file_get_contents($url, false, $http_context); 

通過捲曲只需使用:

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); 
+0

嘗試過太...得到相同的錯誤...並沒有從cURL返回任何東西 – Umair

+0

那麼,你有沒有與其他網址測試過嗎? – felipsmartins

+0

是的,我有一些其他的URL測試,這些加載罰款 – Umair