Skip to content
This repository

A convenience wrapper around PHP's cURL library

branch: master


A convenience wrapper around PHP's cURL library



Via Composer (Preferred)

Create a composer.json file if you don't already have one in your projects root directory and require wcurl:

    "require": {
        "sandeepshetty/wcurl": "dev-master"

Install Composer:

$ curl -s | php

Run the install command:

$ php composer.phar install

This will download wcurl into the vendor/sandeepshetty/wcurl directory.

To learn more about Composer visit

Via an archive

Download the latest version of wcurl:

$ curl -L | tar xvz
$ mv sandeepshetty-wcurl-* wcurl



string wcurl( string $method , string $url [, mixed $query [, mixed $payload [, array $request_headers [, array &$response_headers [, array $curl_opts ]]]]] )



    require 'path/to/wcurl/wcurl.php';

    // Basic GET request
    $response_body = wcurl('GET', '');

    // GET request with query string parameters
    $response_body = wcurl('GET', '', array('page'=>1, 'per_page'=>2));

    // Basic POST request
    // Parameters you want to skip can be passed as NULL. For example, here the query parameter is passed as NULL.
    $body = wcurl('POST', '', NULL, array('q'=>'42', 'format'=>'json'));

    // POST request with a custom request header (Content-Type) and an overriden cURL opt (CURLOPT_USERAGENT)
    // Also passing in a variable ($response_headers) to get back the response headers
    $response_headers = array();
    $response_body = wcurl
        stripslashes(json_encode(array('description'=>'test gist', 'public'=>true, 'files'=>array('42.txt'=>array('content'=>'The Answer to the Ultimate Question of Life, the Universe, and Everything'))))),
        array('Content-Type: application/json; charset=utf-8'),
        $response_headers,  // This variable is filled with the response headers

Something went wrong with that request. Please try again.