How To Check if the cURL PHP extension is loaded

There is not a lot of information about checking if a particular extension is loaded and the few tidbits there are on the internet, are very impractical, so I decided to dig a bit deeper and I came up with my own solution.

The following function returns TRUE if it can find the cURL extension installed, and FALSE if it fails to find it.

// ### Checks for presence of the cURL extension.
function _iscurlinstalled() {
	if  (in_array  ('curl', get_loaded_extensions())) {
		return true;
	}
	else{
		return false;
	}
}

Sample usage:

if (_iscurlinstalled()) echo "cURL is installed"; else echo "cURL is NOT installed";
  1. Dmitry says:

    You may also use ‘function_exists’ function to check that. Simple code will be:
    echo ‘cURL is’.(function_exists(‘curl_open’) ? ” : ‘ not’).’ installed’;

    • myWordPress says:

      Hi Dmitry

      Auch, that code is so much cleaner and simpler. Thank you for that tip, I never even thought to use the function_exists() function.

      Thanks :-)

    • Moondog604 says:

      Dmitry there is an error with your code. I was testing and of course it was giving me a false positive. curl_open is not a function, curl_init is what you should have tested with. Once I made the change I was getting a message saying cURL was enabled.

      echo ‘cURL is’.(function_exists(‘curl_init’) ? ” : ‘ not’).’ installed’;

PRIVACY POLICY: Your privacy is important to us. We will never sell or rent your email address and you can unsubscribe at any time.

If you check the check-box above and leave a comment, you will sign up to our newsletter, but do not worry, we only send out very few e-mails. We usually only send you an e-mail when we launch a new product, want to touch base with our e-mail readers or we have found a really really cool product we want to tell you about.

line
footer
Powered by Wordpress | Designed by Elegant Themes