https://github.com/jabranr/php-curl
Simple PHP client for cURL operations
https://github.com/jabranr/php-curl
composer curl php-client php-curl
Last synced: 3 months ago
JSON representation
Simple PHP client for cURL operations
- Host: GitHub
- URL: https://github.com/jabranr/php-curl
- Owner: jabranr
- License: mit
- Created: 2016-10-09T23:15:57.000Z (about 9 years ago)
- Default Branch: develop
- Last Pushed: 2018-01-27T00:46:37.000Z (almost 8 years ago)
- Last Synced: 2025-05-24T05:12:28.756Z (7 months ago)
- Topics: composer, curl, php-client, php-curl
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP cURL [](https://travis-ci.org/jabranr/php-curl) [](https://packagist.org/packages/jabranr/php-curl) [](https://packagist.org/packages/jabranr/php-curl)
A simple PHP client for cURL operations.
> __Migrating from v1?__ Beware that v2 has breaking changes! Some of the API methods names have changed.
Simply import the library into your project. The best way to do so is to use [Composer](http://getcomposer.org) as following. Otherwise it can simply be downloaded from GitHub and added to the project.
```shell
$ composer require jabranr/php-curl
```
Start using it straight away. (Following example assumes that it was installed via Composer)
```php
setOption(CURLOPT_RETURNTRANSFER, true);
$curl->setOption(CURLOPT_FOLLOWLOCATION, true);
# Set options - method 2
$curl->setOptions(array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true
));
# Execute request, get response and close connection
try {
$response = $curl->execute();
} catch(HttpCurlException $e) {
$curl->getErrorCode(); // -> cURL error number
$curl->getErrorMessage(); // -> cURL error message
# OR
$e->getMessage(); // -> cURL error: [ErrorCode] ErrorMessage
}
# OR get more info and close connection manually
try {
$response = $curl->execute(false);
} catch(HttpCurlException $e) { }
# Get response later
$response = $curl->getResponse();
#
$info = $curl->getInfo();
# Close request
$curl->close();
```
# API
The cURL class exposes following API:
#### `getInfo`
Get cURL request info. `$option` needs to be a valid cURL constant. If none given then it will return an associative array.
```php
$curl->execute(false);
$curl->getInfo($option = null);
$curl->close();
```
#### `getError`
Get cURL request error message.
```php
$curl->getError();
```
#### `getErrorCode`
Get cURL request error code.
```php
$curl->getErrorCode();
```
#### `getErrorMessage`
Get cURL request error message.
```php
$curl->getErrorMessage();
```
#### `getHttpCode`
Get cURL request HTTP status code.
```php
$curl->getHttpCode();
```
#### `getTotalTime`
Get total time taken for a cURL request.
```php
$curl->getTotalTime();
```
#### `getResponse`
Get response for a cURL request.
```php
$curl->getResponse();
```
# License
Feel free to use and send improvements via pull requests. Licensed under the MIT License.
© Jabran Rafique – 2016 – 2017