1

im facing here a problem with this function :

function curl_function($uri) 
{    
    $ch = curl_init($uri);
    $timeout = 30; //set to zero for no timeout
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT, 'mycoreg');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $file_contents = curl_exec($ch);
    $errornum      = curl_errno($ch);
    $info          = curl_getinfo($ch);
    $status        = (int) $info['http_code'];
    if ($errornum !== 0) {
        echo 'Error: ', curl_error($ch);
        $file_contents = NULL;
    }
    curl_close($ch);

    return $file_contents;
}

It gives the error that

"http protocol is not supported or disabled".

plz need help. thanks.

2
  • very strange error, are you sure that https is not supported instead of http ??? Commented Oct 9, 2015 at 10:44
  • 1
    ooops , i've just found the problem , it was a space before http in my url. Commented Oct 9, 2015 at 10:56

2 Answers 2

3

Debug print your URL and ensure it contains no extraneous characters.

In my case, the URL I was using with php curl was quoted. The quote is not printed by curl error handling, so the error is rather confusing and hard to track down.

You can generate this error with the following code:

// wrong
$uri = "'". "http://www.google.com/" . "'"; // quoted string
curl_setopt($ch, CURLOPT_URL, $url);

Now try it with the proper URL format...

// right
$uri = "http://www.google.com/"; // correct format URL
curl_setopt($ch, CURLOPT_URL, $url);
Sign up to request clarification or add additional context in comments.

Comments

1

Update your function like this to avoid a strange errors :)

function curl_function($uri) {
    $uri = trim($uri); 
    // ... your code  
}

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.