icexch / rolling-curl-x
易于使用的 PHP cURL Multi 包装器。
dev-master
2017-10-18 12:39 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-18 03:34:40 UTC
README
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']);
问题
如果您发现任何问题,请告知我。
享受。
