public function addCurl($ch)
{
if (gettype($ch) !== 'resource') {
throw new MultiCurlInvalidParameterException('Parameter must be a valid curl handle');
}
$key = $this->getKey($ch);
$this->requests[$key] = $ch;
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback'));
$code = curl_multi_add_handle($this->mc, $ch);
$this->startTimer($key);
// (1)
if ($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM) {
do {
$this->execStatus = curl_multi_exec($this->mc, $this->running);
} while ($this->execStatus === CURLM_CALL_MULTI_PERFORM);
return new MultiCurlManager($key);
} else {
return $code;
}
}