本文整理匯總了PHP中Connector::_loops方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connector::_loops方法的具體用法?PHP Connector::_loops怎麽用?PHP Connector::_loops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Connector
的用法示例。
在下文中一共展示了Connector::_loops方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: curl_exec_follow
private function curl_exec_follow($ch)
{
if (self::$_loops++ >= self::$_maxLoops) {
self::$_loops = 0;
return false;
}
$data = curl_exec($ch);
$temp = $data;
list($header, $data) = explode("\n\n", $data, 2);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http == 301 || $http == 302) {
$matches = array();
preg_match('/ocation:(.*?)\\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
// print_r($url);
if (!$url) {
self::$_loops = 0;
return $data;
}
$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
if (!$url['scheme']) {
$url['scheme'] = $last_url['scheme'];
}
if (!$url['host']) {
$url['host'] = $last_url['host'];
}
if (!$url['path']) {
$url['path'] = $last_url['path'];
}
$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query'] ? '?' . $url['query'] : '');
// echo "\n redirect to ".$new_url;
//@todo Возможна непредвиденая хуйня.
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $new_url);
return $this->curl_exec_follow($ch);
} else {
self::$_loops = 0;
return $temp;
}
}