Simple PHP client for cURL operations
PHP
Latest commit 72abea0 Feb 9, 2017 @jabranr committed on GitHub fix packagist URL
Permalink
Failed to load latest commit information.
src/HttpUtil
test/HttpUtil
.editorconfig
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

PHP cURL Build Status Latest Stable Version Total Downloads

A simple PHP client for cURL operations.

Simply import the library into your project. The best way to do so is to use Composer as following. Otherwise it can simply be downloaded from GitHub and added to the project.

$ composer require jabranr/php-curl

Start using it straight away. (Following example assumes that it was installed via Composer)

<?php

require 'path/to/vendor/autoload.php';

// Start new cURL request
$curl = new Jabran\HttpUtil\HttpCurlRequest('http://jabran.me');

// Set options - method 1
$curl->setOption(CURLOPT_RETURNTRANSFER, true);
$curl->setOption(CURLOPT_FOLLOWLOCATION, true);

// Set options - method 2
$curl->setOptions(array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true
));

// Execute request and get response
$response = $curl->execute();

// OR
$curl->execute();
$curl->getResponse();

// 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.

$curl->getInfo($option = null);

getError

Get cURL request error message.

$curl->getError();

getErrorCode

Get cURL request error code.

$curl->getErrorCode();

getStatusCode

Get cURL request HTTP status code.

$curl->getStatusCode();

getRequestTime

Get total time taken for a cURL request.

$curl->getRequestTime();

getResponse

Get response for a cURL request.

$curl->getResponse();

License

Feel free to use and send improvements via pull requests. Licensed under the MIT License.

© Jabran Rafique – 2016 – 2017