2017 © Pedro Peláez
 

library mcurl

Simple and powerful curl_multi_* wrapper

image

polonskiy/mcurl

Simple and powerful curl_multi_* wrapper

  • Tuesday, February 25, 2014
  • by polonskiy
  • Repository
  • 0 Watchers
  • 0 Stars
  • 5 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MCurl

Simple and powerful wrapper for curl_multi_*, (*1)

Install

download composer git clone, (*2)

Usage

<?php

$threads = 20;
$options = array(
    'followlocation'  =>  true,  //CURLOPT_FOLLOWLOCATION
    'nobody'          =>  true,  //CURLOPT_NOBODY
);

$queue[] = array(
    'url'             =>  'http://example1.com',  //CURLOPT_URL
    'connecttimeout'  =>  20,                     //CURLOPT_CONNECTTIMEOUT
);
$queue[] = array(
    'url'             =>  'http://example2.com',  //CURLOPT_URL
    'connecttimeout'  =>  10,                     //CURLOPT_CONNECTTIMEOUT
);

$mcurl = new MCurl\Curl($options, $queue, $threads);
while ($response = $mcurl->exec()) {
    $message = "URL: $response->url\n";
    if ($response->error) {
        $message .= "ERROR: $response->error\n";
    } else {
        $message .= "RESPONSE CODE: $response->code\n";
        $message .= "RESPONSE BODY: $response->data\n";
    }
    echo "$message\n";
}

Options

Mcurl options is a array of [curl options][1], but in lowercase and without CURLOPT_ prefix., (*3)

This options is defaults for all requests., (*4)

<?php

$options = array(
    'connecttimeout'  =>  10,  //CURLOPT_CONNECTTIMEOUT
);

$mcurl = new MCurl\Curl($options);

//or

$mcurl = new MCurl\Curl;
$mcurl->options = $options;

Queue

MCurl queue is a php array with curl options., (*5)

This options is specific for each requests., (*6)

<?php

$queue[] = array(
    'url'             =>  'http://example1.com',  //CURLOPT_URL
    'followlocation'  =>  true,                   //CURLOPT_FOLLOWLOCATION
);

$queue[] = array(
    'url'             =>  'http://example2.com',  //CURLOPT_URL
    'followlocation'  =>  false,                  //CURLOPT_FOLLOWLOCATION
    'nobody'          =>  true,                   //CURLOPT_NOBODY
);

$defaultOptions = array();

$mcurl = new MCurl\Curl($defaultOptions, $queue);

//or

$mcurl = new MCurl\Curl;
$mcurl->queue = $queue;

Threads

Threads is a count of parallel connections used by curl., (*7)

<?php

$threads = 20;

$mcurl = new MCurl\Curl($options, $queue, $threads);

//or

$mcurl = new MCurl\Curl;
$mcurl->threads = $threads;

Busy loop

add new urls, (*8)

Response

The Versions

25/02 2014

dev-curlopts

dev-curlopts

Simple and powerful curl_multi_* wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anton Polonskiy

27/09 2013

dev-master

9999999-dev

Simple and powerful curl_multi_* wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anton Polonskiy

27/09 2013

v0.2.0

0.2.0.0

Simple and powerful curl_multi_* wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anton Polonskiy

26/09 2013

v0.1.0

0.1.0.0

Simple and powerful curl_multi_* wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Anton Polonskiy