What is Curl/curl_setopt

Asked

Viewed 8,470 times

9

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 wonder what Curl is, curl_setopt etc., and what are they for (in a general concept, and not just in the presented code).

1 answer

9


The Curl is a tool to create requests on various protocols (including HTTP, HTTPS and FTP, among many others) and get remote content. It exists as a command line tool, and also as a library, the libcurl, that PHP incorporates and exposes through functions curl_*.

The code you showed generates an HTTP request with the POST method for the $submit_url, and the content posted will be the variable $payload. The function curl_setopt defines all parameters of the request. As the parameter CURLOPT_RETURNTRANSFER was defined as true, the function curl_exec (that triggers the request) will return the recovered content from the URL.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.