A Simple Generic PHP cURL Class

cURL is a most excellent library that enables you to communicate across a network with a number of protocols. PHP integrated the cURL library early in its development and nowadays its use is widespread across countless applications. To read more about it you can visit the author’s home page, Daniel Steinberg.

I use a very short generic class that can deal with the majority of my network requests, which is available to you below.

An example request and output is shown below.

Much of the magic in this generic class happens in the curl_setopt_array() function call, which sets the options described on this page. cURL pretty much covers all angles, hence the huge list of options you can pass to your request.

There is also the option of performing multiple requests should you require, which is slightly more efficient.

The nice thing about using cURL for network requests is that there is a huge amount of documentation, and the author continues to provide assistance on various forums and sites to this day.

Leave a Reply

Your email address will not be published. Required fields are marked *