src/curlient/Curlient.php
public function requests($urls, $onSuccess = null) {
		$result   = [0 => [], 1 => [], 2 => []];
		$onFinish = $onStart = $onFail = null;
		if (is_array($onSuccess)) {
			extract($onSuccess);
		}
		$mh = @curl_multi_init();
		if (!$mh) {//初始化失败
			if (is_callable($onFinish)) {
				call_user_func_array($onFinish, $result);
			}

			return $result;
		}
		$requests    = [];
		$onStartCb   = is_callable($onStart);
		$onSuccessCb = is_callable($onSuccess);
		$onFailCb    = is_callable($onFail);
		foreach ($urls as $i => $url) {
			$client               = $this->spawn();
			$client->isSubRequest = true;
			$client->request($url);
			$contiue = true;
			if ($onStartCb) {
				$contiue = call_user_func_array($onStart, [$client]);
			}
			if ($contiue) {
				$requests[ $i ] = $client;
				curl_multi_add_handle($mh, $client->curl);
			} else {
				$result [2] [ $i ] = $client;
			}
		}
		if ($requests) {
			$active = 0;
			do {
				curl_multi_exec($mh, $active);
				if ($active > 0) {
					usleep(50);
				}
			} while ($active > 0);
			/**@var \curlient\Curlient $h */
			foreach ($requests as $i => $h) {
				$rtn             = curl_multi_getcontent($h->curl);
				$h->ready        = false;
				$h->isSubRequest = false;
				if ($rtn === false) {
					$h->content   = '';
					$h->error     = curl_error($h->curl);
					$h->errorCode = curl_errno($h->curl);
					if ($onFailCb) {
						call_user_func_array($onFail, [$h]);
					}
				} else {
					$h->content = $rtn;
					$code       = intval(curl_getinfo($h->curl, CURLINFO_HTTP_CODE));
					if ($code != 200) {
						$h->error     = '[' . $code . ']';
						$h->errorCode = $code;
						if ($onFailCb) {
							call_user_func_array($onFail, [$h]);
						}
						$result [1] [ $i ] = $h;
					} else {
						if ($onSuccessCb) {
							call_user_func_array($onSuccess, [$h]);
						}
						$result [0] [ $i ] = $h;
					}
				}

				curl_multi_remove_handle($mh, $h->curl);
			}
		}

		@curl_multi_close($mh);

		if (is_callable($onFinish)) {
			call_user_func_array($onFinish, $result);
		}

		return $result;
	}
public function requests($urls, $onSuccess = null) {
		$result   = [0 => [], 1 => [], 2 => []];
		$onFinish = $onStart = $onFail = null;
		if (is_array($onSuccess)) {
			extract($onSuccess);
		}
		$mh = @curl_multi_init();
		if (!$mh) {//初始化失败
			if (is_callable($onFinish)) {
				call_user_func_array($onFinish, $result);
			}

			return $result;
		}
		$requests    = [];
		$onStartCb   = is_callable($onStart);
		$onSuccessCb = is_callable($onSuccess);
		$onFailCb    = is_callable($onFail);
		foreach ($urls as $i => $url) {
			$client               = $this->spawn();
			$client->isSubRequest = true;
			$client->request($url);
			$contiue = true;
			if ($onStartCb) {
				$contiue = call_user_func_array($onStart, [$client]);
			}
			if ($contiue) {
				$requests[ $i ] = $client;
				curl_multi_add_handle($mh, $client->curl);
			} else {
				$result [2] [ $i ] = $client;
			}
		}
		if ($requests) {
			$active = 0;
			do {
				curl_multi_exec($mh, $active);
				if ($active > 0) {
					usleep(50);
				}
			} while ($active > 0);
			/**@var \curlient\Curlient $h */
			foreach ($requests as $i => $h) {
				$rtn             = curl_multi_getcontent($h->curl);
				$h->ready        = false;
				$h->isSubRequest = false;
				if ($rtn === false) {
					$h->content   = '';
					$h->error     = curl_error($h->curl);
					$h->errorCode = curl_errno($h->curl);
					if ($onFailCb) {
						call_user_func_array($onFail, [$h]);
					}
				} else {
					$h->content = $rtn;
					$code       = intval(curl_getinfo($h->curl, CURLINFO_HTTP_CODE));
					if ($code != 200) {
						$h->error     = '[' . $code . ']';
						$h->errorCode = $code;
						if ($onFailCb) {
							call_user_func_array($onFail, [$h]);
						}
						$result [1] [ $i ] = $h;
					} else {
						if ($onSuccessCb) {
							call_user_func_array($onSuccess, [$h]);
						}
						$result [0] [ $i ] = $h;
					}
				}

				curl_multi_remove_handle($mh, $h->curl);
			}
		}

		@curl_multi_close($mh);

		if (is_callable($onFinish)) {
			call_user_func_array($onFinish, $result);
		}

		return $result;
	}
批量请求.

@param array               $urls      请求URL数组.
@param null|\Closure|array $onSuccess 请求成功回调，参数为client实例.
也可以是数组，对应相应的回调：
onSuccess => 请求成功回调，参数为client实例.
onFail    => 请求失败回调，参数为client实例.
onStart   => 请求开始回调，参数为client实例.
onFinish  => 所有请求完成回调，三个参数：请求成功client数组，请求失败client数组，未发起请求client数组.

@return array 请求结果（关联数组）.
<p>
0=>[],//请求成功的Client
1=>[],//请求失败的Client
2=>[] //未发起请求的Client,因onStart返回了非真值.
</p>