Download the PHP package drewlabs/curl-client without Composer
On this page you can find all versions of the php package drewlabs/curl-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package curl-client
cURL Client
This project tends to implements an Object oriented PHP cURL client and provides a PSR18 implementation based on the cURL client object.
Installation
Recommended way to install the library is by using PHP package manager composer
running the command below:
composer require drewlabs/curl-client
Usage
The library comes with 2 cURL client, the 1st being an object oriented cURL class and PSR18 compatible client based on PHP cURL library.
OOP cURL client
To create a new instance of the client, use the class constructor:
This will create a new client instance and initialize a new curl session. Developpers can pass a base url to the client instance to define the host server url:
Curl Options
cURL options allow developpers to customize cURL request sent to the application server. Using Client::setOption()
or Client::setOptions()
for array like options, developpers can customize cURL requests being sent to the server.
In order to pass cURL options as array, we use the setOptions()
array method:
Sending cURL request
The client provides developpers with Client::send()
method to send HTTP request to server:
Sometimes you may have constructed the curl request and wish to simply execute the curl request. To do so the client mimic the curl exec()
method by providing Client::exec()
method for sending request to server.
- Helper methods
The client comes with some helper method for basic curl HTTP options like, CURLOPT_URL
, \CURLOPT_SSL_VERIFYPEER
, \CURLOPT_HTTP_VERSION
etc... Below is a brief API definition for most common use cases:
Client::setRequestUri(string $url)
- Set the request URIClient::setRequestMethod(string $method)
- Set the request methodClient::setProtocolVersion(string $version)
- Set the HTTP protocol versionClient::withAutoReferer()
- Automatically set the auto referer header where it follows redirectClient::followLocation()
- Follows any location redirect unless \CURLOPT_MAXREDIR is sets.Client::maxRedirects(int $n)
- The number of redirect to be followed by the cURL clientClient::proxy($proxy, $port = null, $username = null, $password = null)
- Defines an HTTP proxy through which the request is forwarded.Client::setUserAgent($user_agent)
- Defines the request user agentClient::timeout(int $milliseconds)
- Timeout the request for a given millisecondsClient::verifyHost()
- Make sure the cURL client validate host domain and SSL certificate
Note
By default the cURL connection is closed the PHP runtime when the object is destructed. If developper which to close the curl session, or reset cURL parameters, the instance provides with close()
and release()
method for each specific case:
All versions of curl-client with dependencies
ext-curl Version *