0

I am scraping http://www.beautyinzone.net/.

I am using simple file_get_contents() to load this URL.

Its working perfectly on my localhost. But it does not work when I upload on my live server.

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

If I open some other URL it works fine.

URL

I have tried with cURL as well but that shows empty page, returns nothing.

One thought came in my mind that maybe I am blocked, but it should not be like that that said website using my servers.

What possible issue can be preventing me loading that URL?

Umair Ayub
  • 19,358
  • 14
  • 72
  • 146

3 Answers3

1

Its working for me. Try to get the error by below code

if (!$content = file_get_contents("http://www.beautyinzone.net/")) {
    $error = error_get_last();
    echo $error['message'];
} else {
    echo "working fine";
}
Ravinder Reddy
  • 3,869
  • 1
  • 13
  • 22
1

Because the remote server is delaying to reply you've re received a http timeout error. it's just normal.

TCP sockets has timeout set and when this timeout is reached a timeout error is raised. Generally the timeout is 30 seconds (By default the default_socket_timeout php.ini setting is used).

Maybe you want set (increase) a custom timeout yourself:

<?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);

Via cURL just use:

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); 
felipsmartins
  • 13,269
  • 4
  • 48
  • 56
0

Try this cURL snippet

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
}

Also, check out this thread

Community
  • 1
  • 1
Amous
  • 534
  • 5
  • 18