When I first started getting into this, I read a lot on PHP and remember clearly having my eyes go crossed when I came across code like this —
So, in a nutshell, Curl is a very popular Linux/Unix command line program for doing things across the internet - downloading things, uploading things, pinging remote servers with requests, etc. Curl has a wealth of options that you can set with command line flags (-I
to only get response headers, -D
to post form data, -X
to specify a HTTP method, etc).
PHP has a built in function for working with Curl, thereby making it easy to programmatically make HTTP calls to other servers. Of course, to really be able to use Curl in a way that’s analogous to it’s usage on the command line, you need a way to set those flags. curl_init()
sets all that up for you, and all you really need to do after that is set whatever flags you need in calls to curl_setopt()
.
See the docs here - https://php.net/manual/en/function.curl-init.php.