2017 © Pedro Peláez
 

library php-curl-wrapper

A wrapper for cURL that makes it easy to use/manage requests and responses.

image

weidizhang/php-curl-wrapper

A wrapper for cURL that makes it easy to use/manage requests and responses.

  • Monday, September 5, 2016
  • by ebildude123
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP-Curl-Wrapper

Created by Weidi Zhang, (*1)

About

Easily make HTTP requests and get response information with cURL., (*2)

Installation

composer require weidizhang/php-curl-wrapper:dev-master

Usage

First, require the autoloader and use the Curl class., (*3)

require "vendor/autoload.php";
use weidizhang\PHPCurlWrapper\Curl;

Create a new Curl object, (*4)

$curl = new Curl();

Changing default behavior

use weidizhang\PHPCurlWrapper\Behavior;

$curl->setBehavior( ... );

Options: KEEP_HEADERS, CLEAR_HEADERS., (*5)

See src/Behavior.php to see what these do., (*6)

Default: CLEAR_HEADERS, (*7)

Setting various cURL options

$curl->setReferer( ... );
$curl->setUserAgent( ... );
$curl->setHeader( name, value );
$curl->setHeaders( array(
    "Header1: value1",
    "Header2: value2"
) );
$curl->unsetHeader( name );
$curl->setCookieFile( filename or path );
$curl->enableSSLVerify();
$curl->disableSSLVerify();

Setting custom cURL options

You can pass in the option either as a constant or string., (*8)

All these do the same thing:, (*9)

$curl->setOption(CURLOPT_FRESH_CONNECT, true);
$curl->setOption("CURLOPT_FRESH_CONNECT", true);
$curl->setOption("FRESH_CONNECT", true);

Making a request

$response = $curl->request( type, url, query [optional], options [optional] );

type = GET, POST, HEAD, PUT, etc. Custom request types are supported., (*10)

url = URL., (*11)

query = Query to send, it can be an array or string., (*12)

options = An array of curl options to set. It calls $curl->setOption( ... ); for them., (*13)

Getting cURL handle

If you need access to the cURL handle for whatever reason:, (*14)

$curl->getHandle();

Handling the response

Getting body data: (Both work), (*15)

$body = $response;
$body = $response->getBody();

Getting cURL request information:, (*16)

$info = $response->getInfo();

Getting all headers:, (*17)

$headers = $response->getHeaders();

Getting a specific header:, (*18)

$header = $response->getHeader( name );

Checking for errors (Usually not necessary):, (*19)

if ($response->hasError()) {
    $error = $response->getError();
}

License

Please read LICENSE.md to learn about what you can and cannot do with this source code., (*20)

The Versions

05/09 2016

dev-master

9999999-dev

A wrapper for cURL that makes it easy to use/manage requests and responses.

  Sources   Download

CC BY-NC-ND 4.0

The Requires

  • php >=5.5.0