Download the PHP package dcarbone/curl-plus without Composer
On this page you can find all versions of the php package dcarbone/curl-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dcarbone/curl-plus
More information about dcarbone/curl-plus
Files in dcarbone/curl-plus
Package curl-plus
Short Description Object wrapper for PHP's CURL Library
License Apache-2.0
Homepage https://github.com/dcarbone/curl-plus
Informations about the package curl-plus
curl-plus
A simple wrapper around PHP's cURL implementation. It does not do anything magical, and is intended to be as simple as possible
Installation
This lib is designed to be used with Composer
"require" entry:
CurlPlus Helper
To make executing and retrieving data from HTTP requests easier, I have created the CURL helper class.
Helper Basics:
All of the methods present below have a few default CURL options set, that you can override if needed:
- With the exception of HEAD and OPTIONS requests, all methods set
CURLOPT_RETURNTRANSFER
to true by default. - ALL methods set
CURLOPT_FOLLOWLOCATION
to true by default. - POST, PUT, and DELETE requests specify a default Request Content-Type header value of
application/x-www-form-urlencoded
- POST, PUT, and DELETE requests allow specification of a request body. This may either be a string, or associative array of "param" => "value", or an object. It will be turned into a string utilizing http_build_query.
- ALL methods return an instance CurlPlusResponse
- ALL methods allow overriding of CURLOPT and Request Header values used via optional array arguments. These will be merged with the defaults, with user-specified values receiving preference.
Usage Basics
This class is as close as PHP gets to a "static" class. It is abstract, and therefore cannot be instantiated on its own, and is intended to be used as such:
The above will download photographic evidence of life saving tamales and output the image.
Check out the source of CURL to get a better look at all available methods and arguments.
Using the client directly
The most simple implementation of this class would be something like the following:
The above will simply execute a GET request and store the response in memory, rather than in the output buffer.
Constructor
The CurlPlusClient constructor takes 3 optional arguments:
- $url - string, the query endpoint
- $curlOpts - array, set of CURLOPT_ values
- $requestHeaders - array, associative array of $param=>$value strings that will be sent in the request
These are all optional parameters.
Note: If you set both the $url and CURLOPT_URL properties on construction, the constructor will use to the CURLOPT_URL value.
As stated above, all of those are optional arguments. You may simply construct the object with no params if you wish.
Post-construct, the methods:
...will probably be the ones you use the most often.
Check out the CurlPlusClient source for more information.