2017 © Pedro Peláez
 

library curl

A Simple http library uses curl

image

oksuz/curl

A Simple http library uses curl

  • Tuesday, April 21, 2015
  • by oksuz
  • Repository
  • 3 Watchers
  • 2 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

A Simple Php Curl Library

Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Installation

Composer is recommended for installation., (*2)

In one command line :, (*3)

composer require oksuz/curl dev-master

Or via editting your composer.json, (*4)

{
    "require": {
        "oksuz/curl": "dev-master"
    }
}
composer update

Examples

Single Requests

GET

$cli = new \Oksuz\Curl\Request("http://example.org");
/** @var \Oksuz\Curl\Response $result */
$result = $cli->result();

//echo $result->getHeader();
//echo $result->getStatusCode();
echo $result->getResponse();

POST

$cli = new \Oksuz\Curl\Request("http://example.org")
/** @var \Oksuz\Curl\Response $result */
$result = $cli->post(array("username" => "foo", "password" => "bar"))
    ->addReferer("http://www.google.com/?q=example")
    ->setOpt(CURLOPT_USERAGENT, "firefox/2.0.16") // you can add php's CURL_CONSTANTS
    ->result();

Also available put and delete method, (*5)

Runing Multiple Curl Requests

$clients = array();
$clients[] = new \Oksuz\Curl\Request("http://example1.org");
$clients[] = new \Oksuz\Curl\Request("http://example2.org");
$clients[] = new \Oksuz\Curl\Request("http://example3.org");
$runner = new \Oksuz\Curl\Runner();
/** @var Array $result contains \Oksuz\Curl\Response */
$result = $runner->runMultiple($cli);

More Complex Example

$curl = new \Oksuz\Curl\Request();
$response = $curl->url("http://www.example.org/login")
    ->post(array("username" => "user", "password" => "password"))
    ->addCookieSupport()
    //OR ->addCookieSupport("/path/to/cookiejar_cookiefile.txt")
    ->result();

if (200 == $response->getStatusCode()) {
    $resp = $curl->url("http://www.example.com/private_area")
    ->get(array("page" => 1, "do" => "show")) // http://www.example.com/private_area?page=1&do=show
    ->addHeader(array("HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"))
    ->addCookie(array("cookie_name" => "cookie_value"))
    ->setBasicAuth("username", "password")
    ->result();

    var_dump($resp);
}

Default Values

CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36",
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,

The Versions

21/04 2015

dev-master

9999999-dev https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl scraping http request crawling

21/04 2015

1.0.2

1.0.2.0 https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl scraping http request crawling

18/11 2014

1.0.1

1.0.1.0 https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl scraping http request crawling

16/11 2014

1.0.0

1.0.0.0 https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl http request

12/11 2014

0.0.2

0.0.2.0 https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl http request

12/11 2014

0.0.1

0.0.1.0 https://github.com/oksuz/curl

A Simple http library uses curl

  Sources   Download

The Requires

  • php >=5.3.0
  • ext-curl *

 

curl http request