2017 © Pedro Peláez
 

library curly

Parallel cURL Wrapper for PHP

image

alixaxel/curly

Parallel cURL Wrapper for PHP

  • Wednesday, September 17, 2014
  • by alixaxel
  • Repository
  • 2 Watchers
  • 2 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

curly

Parallel cURL Wrapper for PHP, (*2)

Requirements

  • PHP 5.4+
  • cURL Extension

Installation (via Composer)

Add the following dependency in your composer.json file:, (*3)

{
    "require": {
        "alixaxel/curly": "*"
    }
}

And then just run composer install or composer update., (*4)

Usage (Single Requests)

<?php

use alixaxel\curly\CURL;

$url = 'http://httpbin.org/post',
$data = [
    'foo' => sprintf('@', __FILE__),
    'bar' => 'baz',
];

var_dump(CURL::Uni($url, $data, 'POST'));

Usage (Multiple Requests)

<?php

use alixaxel\curly\CURL;

$url = 'http://httpbin.org/post',
$data = [
    'foo' => sprintf('@', __FILE__),
    'bar' => 'baz',
];

$handles = [];

for ($i = 0; $i < 16; ++$i)
{
    $handles[$key = uniqid()] = CURL::Uni($url, $data, 'POST', null, null, 0);
}

$parallel = 4; // number of requests to make in parallel
$throttle = 1; // wait at least 1 second per each $parallel requests

print_r(CURL::Multi($handles, null, $parallel, $throttle)); // original keys are preserved

Usage (Multiple Requests with Callback)

<?php

use alixaxel\curly\CURL;

$url = 'http://httpbin.org/post',
$data = [
    'foo' => sprintf('@', __FILE__),
    'bar' => 'baz',
];

$handles = [];

for ($i = 0; $i < 16; ++$i)
{
    $handles[$key = uniqid()] = CURL::Uni($url, $data, 'POST', null, null, 0);
}

$parallel = 4; // number of requests to make in parallel
$throttle = 1; // wait at least 1 second per each $parallel requests

$result = CURL::Multi($handles, function ($response, $info, $id) {
    var_dump($id, $response);
}, $parallel, $throttle);

print_r($result); // each key will have the return value of the lambda callback 

Changelog

  • 0.1.0 ~~initial release~~
  • 0.2.0 ~~added XPathify() utility method~~

Credits

XPathify() is based on visionmedia/php-selector., (*5)

License (MIT)

Copyright (c) 2014 Alix Axel (alix.axel+github@gmail.com)., (*6)

The Versions

17/09 2014

dev-master

9999999-dev https://github.com/alixaxel/curly/

Parallel cURL Wrapper for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • lib-curl *

 

The Development Requires

by Alix Axel

curl curl_multi