php-multi-curl 处理并行 http 请求的 PHP 库 项目简介
php-multi-curl 是一个简单而有效的库,封装了 curl_multi_*,用于处理并行的 http 请求。要求PHP 5.4 or laterPHP cURL extension用法//require '../vendor/autoload.php';
use Hhxsv5\PhpMultiCurl\Curl;
use Hhxsv5\PhpMultiCurl\MultiCurl;
//Single http request
$options = [//The custom options of cURL
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_USERAGENT => 'Multi-cURL client v1.5.0',
];
$c = new Curl($options);
$c->makeGet($getUrl);
$response = $c->exec();
if ($response->hasError()) {
//Fail
var_dump($response->getError());
} else {
//Success
var_dump($response->getBody());
}
//Reuse $c
$c->makePost($postUrl);
$response = $c->exec();
if ($response->hasError()) {
//Fail
var_dump($response->getError());
} else {
//Success
var_dump($response->getBody());
}
use Hhxsv5\PhpMultiCurl\Curl;
use Hhxsv5\PhpMultiCurl\MultiCurl;
//Single http request
$options = [//The custom options of cURL
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_USERAGENT => 'Multi-cURL client v1.5.0',
];
$c = new Curl($options);
$c->makeGet($getUrl);
$response = $c->exec();
if ($response->hasError()) {
//Fail
var_dump($response->getError());
} else {
//Success
var_dump($response->getBody());
}
//Reuse $c
$c->makePost($postUrl);
$response = $c->exec();
if ($response->hasError()) {
//Fail
var_dump($response->getError());
} else {
//Success
var_dump($response->getBody());
}