John Paul
John Paul

Reputation: 59

Detect if cURL works?

This is the warning.

Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /.../file.php on line 41

This is what I am using to detect cURL. If cURL isn't enabled a work around is triggered.

function curlEnabled() {
    if (ini_get('safe_mode') == 1)
        return 0;

    return in_array('curl', get_loaded_extensions());
}

I am finding it very difficult to test this function effectively do to a lack of hosting with safe mode enabled or cURL disabled.

Could someone tell me.

  1. Does the function actually detect PHP safe_mode?
  2. It detects whether cURL is loaded right?

Finally, how would this function be improved to catch the 'cannot be activated' error and return 0?

Upvotes: 3

Views: 20304

Answers (1)

Christian
Christian

Reputation: 28124

That seems to work correctly with safe_mode.

To check CURL, you can either look for it in the loaded extensions (as you did), or simply:

function_exists('curl_init');

With regards to the error message, I'm not sure what you're asking. Do you want to suppress the error message?

You can do something like:

$old=error_reporting(0); // turn off error reporting
// do whatever that causes errors
error_reporting($old);   // turn it back on

Upvotes: 6

Related Questions