What is curl / curl_setopt

8

I'm doing an integration with MailChimp, and I came across this code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload));

I wanted to know what curl, curl_setopt etc., and what they are for (in a general concept, not just the code presented).

    
asked by anonymous 16.04.2015 / 15:06

1 answer

8

cURL is a tool for creating requests on various protocols (including HTTP, HTTPS and FTP, among many others) and get content remote. It exists as a command-line tool, and also as a library, the libcurl , that PHP embeds and exposes through curl_* functions.

The code you've generated generates an HTTP request with the POST method for the URL in $submit_url , and the posted content will be the $payload variable. The curl_setopt function defines all request parameters. Because CURLOPT_RETURNTRANSFER was set to true , the curl_exec function (which triggers the request) will return the retrieved content from the URL.

    
16.04.2015 / 15:16