Download the PHP package samuraee/easycurl without Composer
On this page you can find all versions of the php package samuraee/easycurl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samuraee/easycurl
More information about samuraee/easycurl
Files in samuraee/easycurl
Package easycurl
Short Description Super easy and flexible wrapper class for PHP cURL extension
License MIT
Homepage https://github.com/samuraee/EasyCurl
Informations about the package easycurl
EasyCurl
Super easy and flexible wrapper class for PHP 7.0+ cURL extension
See php.net/curl for more information about the libcurl extension for PHP.
It's a fairly simple library, so if you want something more powerful take a look at Guzzle.
Install
via Composer (recommended)
composer require samuraee/easycurl '~1.0'
via download
Just grab the latest release.
Usage
Initialization
Performing request
The EasyCurl object supports 5 types of requests: HEAD, GET, POST, PUT, and DELETE. You must specify an url to request and optionally specify an associative array or query string of variables to send along with it.
To use a custom request methods, you can call the request
method:
Examples:
All requests return response body as is or throw a EasyCurlException if an error occurred.
Performing POST/PUT request with raw payload
Some times you need to send not encoded POST params, but a raw JSON or other raw data format.
Note that data is sending as as, without any URL-encoding manipulation. Keep that in mind.
You might also need to change the content type header for those types of request:
It depends on API server-side you are working with.
Getting additional information about request sent
This will give you associative array with following keys:
url
- Last effective URLcontent_type
- Content-Type: of downloaded object, NULL indicates server did not send valid Content-Type: headerhttp_code
- Last received HTTP codeheader_size
- Total size of all headers receivedrequest_size
- Total size of issued requests, currently only for HTTP requestsfiletime
- Remote time of the retrieved document, if -1 is returned the time of the document is unknownssl_verify_result
- Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEERredirect_count
- Number of redirects it went through if CURLOPT_FOLLOWLOCATION was settotal_time
- Total transaction time in seconds for last transfernamelookup_time
- Time in seconds until name resolving was completeconnect_time
- Time in seconds it took to establish the connectionpretransfer_time
- Time in seconds from start until just before file transfer beginssize_upload
- Total number of bytes uploadedsize_download
- Total number of bytes downloadedspeed_download
- Average download speedspeed_upload
- Average upload speeddownload_content_length
- content-length of download, read from Content-Length: fieldupload_content_length
- Specified size of uploadstarttransfer_time
- Time in seconds until the first byte is about to be transferredredirect_time
- Time in seconds of all redirection steps before final transaction was startedcertinfo
- There is official description for this field yetrequest_header
- The request string sent. For this to work, add the CURLINFO_HEADER_OUT option
You can also easily fetch any single piece of this array:
Cookie sessions
To maintain a session across requests and cookies support you must set file's name where cookies to store:
This file must be writable or the EasyCurlException will be thrown.
Basic configuration options
You can easily set the referer, user-agent, timeout and whether or not follow redirects:
HTTP Basic Authentication
You can set a username and password for use in HTTP basic auth:
Setting custom headers
You can set custom headers to send with the request:
Or use a single array:
Setting custom cURL options
You can set/override any cURL option (see the curl_setopt documentation for a list of them):
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
All versions of easycurl with dependencies
ext-curl Version *