Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alixaxel/curly

Asynchronous cURL Wrapper for PHP
https://github.com/alixaxel/curly

Last synced: 3 days ago
JSON representation

Asynchronous cURL Wrapper for PHP

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/alixaxel/curly.svg?branch=master)](https://travis-ci.org/alixaxel/curly/)

#curly

Parallel cURL Wrapper for PHP

##Requirements

- PHP 5.4+
- cURL Extension

##Installation (via Composer)

Add the following dependency in your composer.json file:

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

And then just run `composer install` or `composer update`.

##Usage (Single Requests)

```php
sprintf('@', __FILE__),
'bar' => 'baz',
];

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

##Usage (Multiple Requests)

```php
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
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](https://github.com/visionmedia/php-selector/).

##License (MIT)

Copyright (c) 2014 Alix Axel ([email protected]).