The cURL extension of PHP helps our website to communicate with other websites and APIs with many different types of protocols, including http, https, ftp, gopher, telnet, dict, file, and ldap protocols. cURL (client URL) is a library created by Daniel Stenberg.
We can also use cURL to perform HTTP form based upload, proxies, cookies, and user+password authentication.
Error message when cURL is not enabled when WordPress’s AMP plugin is activated.
Or if you use the library’s function such as curl_init(), you will see this error message:
Fatal error: Call to undefined function curl_init()
Steps to enable cURL
In order to use cURL in any PHP applications, we need to enable it in
- Open php.ini. The location of this file depends the OS and software you use. For example, it should be
C:\xampp\php\php.inifor XAMPP or
/etc/php/7.2/apache2/php.inifor Debian Apache. You can pin point the exact location by using
phpinfo()function in a PHP file.
- Browse to
- Remove the
;character before extension to register cURL extension.
- Restart Apache or nginx server.
If cURL is enabled successfully, you will see this part when print out
An example of how to use cURL:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.google.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); echo $output; curl_close($ch);