2

Using

$curl_handle = curl_init();
curl_setopt( $curl_handle, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $curl_handle, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl_handle, CURLOPT_HEADER, 1 );
curl_setopt( $curl_handle, CURLOPT_VERBOSE, 1 );
curl_setopt( $curl_handle, CURLOPT_URL, "https://www.someurl.com" );
$buffer = curl_exec( $curl_handle );
print_r( curl_getinfo ( $curl_handle ) );

I get

Array ( [url] => https://www.someurl.com [content_type] => [http_code] => 0 
[header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0
[redirect_count] => 0 [total_time] => 10.00005 [namelookup_time] => 0.001271 
[connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 
[speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 
[upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 ) 

So it seems not to be connecting to the server, yet the identical code works fine from my local machine. Is there any way to get more information? My suspicion is that either my webhost is blocking the outgoing connection or the server I'm trying to connect to is refusing the connection (at one stage a few months back they were doing this but I was at least receiving 403 messages, now I'm getting nothing). I've tried increasing the timeout but same result (with 10 replaced by the timeout in the response). Also, the namelookup_time seems very small, so I wonder if that is failing somehow?

Thanks.

UPDATE: I can retrieve google.com fine from both my web server and my local machine so it seems it's not my webhost blocking me. I have tried numerous proxies and the page is retrieved from my local machine but not on my webserver (identical results to what I posted above). I can't work out how to connect via IP, but the namelookup_time is much much smaller than it is for the google.com page. Given this small amount of extra info, does anyone have any other ideas?

Gary Garygary
  • 141
  • 2
  • 14
  • 1
    Is it possible that your machine and your server have different proxy settings? That is: may it happen that curl will pick up the proper settings from the environment if running on your machine? – Udo Klein Mar 23 '13 at 07:59
  • 1
    Try requesting via some proxies - you will see if you IP was blocked or not. Also, add valid User Agent. – Ranty Mar 23 '13 at 07:59
  • I'd suggest trying to fetch something like Google.com's front-page - or what have you, and then if that doesn't work try it by IP to make sure it isn't a DNS issue. Some hosts to block certain (or many) outgoing/income ports, so you'll want to try the aforementioned test first to see if you need to contact them to see if they are (and if they won't allow them then you'll need a proxy). – BrianH Mar 23 '13 at 08:15
  • @BrianDHall checking by IP seems like a good idea. The actual URL i'm using is of the form https://www.someurl.com/dir/dir/file.ext?etc. Forgive my noobiness but how do I try to connect to this link via IP only? Using https://123.123.123.123/dir/dir/file.ext?etc connects but only to the base https://123.123.123.123/ it seems to ignore the rest. – Gary Garygary Mar 23 '13 at 09:55
  • @GaryGarygary I forgot it wasn't trivial to use an IP instead of a URL. Try this: http://stackoverflow.com/questions/6398149/curl-in-php-and-ip-address – BrianH Mar 24 '13 at 22:31

1 Answers1

0

you can use file_get_contents to get data from url

Umur Kontacı
  • 35,403
  • 8
  • 73
  • 96
Ankit Agrawal
  • 6,034
  • 6
  • 25
  • 49