WP-Mix

A fresh mix of code snippets and tutorials

Check for PHP cURL

Quick snippet for checking whether or not PHP’s cURL is available on the server.

First check to see whether or not curl is found in the array of loaded extensions:

$has_curl = in_array('curl', get_loaded_extensions());

Then you can use the $has_curl as a condition for any cURL-specific functionality. For example:

if ($has_curl) {
	// do something with cURL
} else {
	// do something with an alternate method
}

This logic helps to eliminate errors and keep things running smooth. Always a plus.

Update (2015/09/06): this also should work to test for cURL:

if (function_exists('curl_init')) {
	// do something with cURL
}

Way more simple and should be just as effective :)

★ Pro Tip:

USP ProSAC Pro