2017 © Pedro Peláez
 

library async-request

Asynchronous cURL library for PHP with reasonable API

image

async-request/async-request

Asynchronous cURL library for PHP with reasonable API

  • Saturday, October 29, 2016
  • by MartinMajor
  • Repository
  • 4 Watchers
  • 18 Stars
  • 3,169 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 31 % Grown

The README.md

AsyncRequest

Asynchronous cURL library for PHP with reasonable API., (*1)

Build Status Latest stable License, (*2)

PHP is by default single-thread language but when it comes to HTTP requests it is not very convenient to do them in serial. cURL implementation in PHP offers functions for multi requests but with terrible C-style API. This library wraps those functions into modern object-oriented event-driven API., (*3)

Requirements

async-request/async-request version 1.x requires PHP 7.1+ with cUrl extension enabled., (*4)

If you are using PHP5.4+ you can use async-request/async-request version 0.x., (*5)

Installation

You can easily install the newest version using Composer:, (*6)

composer require async-request/async-request

Simple example

$urls = [
    'http://www.example.com',
    'http://www.example.org',
];

$asyncRequest = new AsyncRequest\AsyncRequest();

foreach ($urls as $url) {
    $request = new AsyncRequest\Request($url);
    $asyncRequest->enqueue($request, function(AsyncRequest\Response $response) {
        echo $response->getBody() . "\n";
    });
}

$asyncRequest->run();

Advanced features

You can specify number of requests that can run in parallel:, (*7)

$asyncRequest->setParallelLimit(5);

You can add other requests in callback function:, (*8)

$callback = function(AsyncRequest\Response $response, AsyncRequest\AsyncRequest $asyncRequest) {
    $asyncRequest->enqueue(new AsyncRequest\Request('http://www.example.com'));
};

You can specify priority of each request and requests with higher priority will be called first:, (*9)

$asyncRequest->enqueueWithPriority(10, $request, $callback);

If you want to use some cURL options, it is as easy as this:, (*10)

$request = new AsyncRequest\Request($url);
$request->setOption(CURLOPT_POST, true);

And if you want some special behavior or some additional data in Response, you can always create your own Request object by implementing IRequest interface., (*11)

The Versions

29/10 2016

v0.1.x-dev

0.1.9999999.9999999-dev

Asynchronous cURL library for PHP with reasonable API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • lib-curl *

 

The Development Requires

29/10 2016

v0.1.0

0.1.0.0

Asynchronous cURL library for PHP with reasonable API

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • lib-curl *

 

The Development Requires

29/10 2016

dev-master

9999999-dev

Asynchronous cURL library for PHP with reasonable API

  Sources   Download

MIT

The Requires

  • php >=7.1.0
  • lib-curl *

 

The Development Requires

29/10 2016

v1.0.0

1.0.0.0

Asynchronous cURL library for PHP with reasonable API

  Sources   Download

MIT

The Requires

  • php >=7.1.0
  • lib-curl *

 

The Development Requires