0

I've looked at the prior posts about cURL and HTTP code 0, but they aren't helping.

I can cURL into www.bambooping.com with script below from localhost - ie, test_curl.php on localhost calls test_curl2.php on bambooping.com. However, if I run it on bambooping.com, I get HTTP code 0. (I know calling this on same host is dumb - it's just to isolate problem.)

On bambooping.com safe_mode is not set, and curl is compiled in (ie, should be since I can cURL in). This is very strange - the calling host is preventing the cURL. Why would calling out with cURL fail like this, yet calling into that same host with cURL be ok?

test_curl.php:

<?php
error_reporting(E_ALL); ini_set("display_errors", 1);
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
}

// OK cool - then let's create a new cURL resource handle
$ch = curl_init();

// Now set some options (most are optional)

// Set URL to download
curl_setopt($ch, CURLOPT_URL, $Url);

// Set a referer
//    curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);

// make it blank - then it is ignored - otherwise, checked and error returned!
curl_setopt($ch, CURLOPT_REFERER, '');

// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);

// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

//    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

// Download the given URL, and return output
$output = curl_exec($ch);

print_r(curl_getinfo($ch));

// Close the cURL resource, and free system resources
curl_close($ch);

return $output;
}

$str = curl_download("http://www.bambooping.com/test_curl2.php");
echo $str;
?>

test_curl2.php

<?php
echo "I am here";
?>

The curl_getinfo is:

Array
(
[url] => http://www.bambooping.com/test_curl2.php
[content_type] => 
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 4.3E-5
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)

Ideas? I'm fresh out... Thanks -

2 Answers 2

2

Please check there is a curl error

it's say the problem to you

<?php
    if(curl_errno($ch))  echo 'Curl error: ' . curl_error($ch);  
?>
Sign up to request clarification or add additional context in comments.

Comments

0

The server for www.bambooping.com is probably sitting behind a firewall that prevents outgoing HTTP requests. Even though it's the same server, the request still needs to go out into the wild to resolve the DNS.

You could either edit the hosts file on your server to include 127.0.0.1 www.bampooing.com. Or you could change the URL to http://127.0.0.1/test_curl2.php, as this localhost domain is probably not blocked by the firewall.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.