marcushat/rolling-curl-x

PHP的cURL Multi包装器,易于使用。

dev-master 2018-04-17 12:39 UTC

This package is auto-updated.

Last update: 2020-01-10 15:30:59 UTC


README

RollingCurlX

Rolling Curl X是Rolling Curl包装器cURL Multi的分支。它旨在使PHP中的并发HTTP请求尽可能简单。

许可

MIT

版本

3.0.0

要求

PHP 5.4+

如何使用

使用这个类非常简单。

首先,用您希望同时打开的最大并发请求数初始化类。此之后的所有请求都将排队,直到其中一个完成。

$RCX = new RollingCurlX(10);

然后向队列中添加一个请求

$url = 'http://www.google.com/search?q=apples';
$post_data = ['user' => 'bob', 'token' => 'dQw4w9WgXcQ']; //set to NULL if not using POST
$user_data = ['foo', $whatever];
$options = [CURLOPT_FOLLOWLOCATION => false];
function callback_functn($response, $url, $request_info, $user_data, $time) {
    $time; //how long the request took in milliseconds (float)
    $request_info; //array returned by curl_getinfo($ch), plus a couple extras
}

$RCX->addRequest($url, $post_data, 'callback_functn', $user_data, $options, $headers);

发送请求。阻塞,直到所有请求完成或超时。

$RCX->execute();

看?很简单。这基本上就是一个简单请求的所有内容。

如果您需要更多,还有更多...

//Set a timeout on all requests:
$RCX->setTimeout(3000); //in milliseconds

//To set options for all requests(will be overridden by individual request options):
$RCX->setOptions([$curl_options]);

//To do the same with http headers:
$RCX->setHeaders(['Content-type: application/xml', 'Authorization: gfhjui']);

问题

如果您发现任何问题,请告知我。

享受。

http://www.github.com/marcushat/rollingcurlx