本文整理汇总了PHP中curl_copy_handle函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_copy_handle函数的具体用法?PHP curl_copy_handle怎么用?PHP curl_copy_handle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_copy_handle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ping
/**
* @since 1.0
*
* @return boolean
*/
public function ping()
{
if (curl_getinfo($this->handle, CURLINFO_EFFECTIVE_URL) === '') {
return false;
}
// Copy the handle to avoid diluting the resource
$handle = curl_copy_handle($this->handle);
curl_setopt_array($handle, array(CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER, true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_FRESH_CONNECT => false, CURLOPT_FAILONERROR => true));
curl_exec($handle);
return curl_errno($handle) == 0;
}
示例2: save
function save($curpass, $passwd)
{
$rcmail = rcmail::get_instance();
if (is_null($curpass)) {
$curpass = $rcmail->decrypt($_SESSION['password']);
}
if ($ch = curl_init()) {
// initial login
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => 'https://ssl.df.eu/chmail.php', CURLOPT_POST => true, CURLOPT_POSTFIELDS => array('login' => $rcmail->user->get_username(), 'pwd' => $curpass, 'action' => 'change')));
if ($result = curl_exec($ch)) {
// login successful, get token!
$postfields = array('pwd1' => $passwd, 'pwd2' => $passwd, 'action[update]' => 'Speichern');
preg_match_all('~<input name="(.+?)" type="hidden" value="(.+?)">~i', $result, $fields);
foreach ($fields[1] as $field_key => $field_name) {
$postfields[$field_name] = $fields[2][$field_key];
}
// change password
$ch = curl_copy_handle($ch);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
if ($result = curl_exec($ch)) {
if (strpos($result, 'Einstellungen erfolgreich') !== false) {
return PASSWORD_SUCCESS;
}
} else {
return PASSWORD_CONNECT_ERROR;
}
} else {
return PASSWORD_CONNECT_ERROR;
}
} else {
return PASSWORD_CONNECT_ERROR;
}
return PASSWORD_ERROR;
}
示例3: __clone
public function __clone()
{
$this->clearFileIfTemp();
$handle = curl_copy_handle($this->getHandle());
if (!$handle) {
throw new \Exception('Unable to copy cURL handle.');
}
$this->setHandle($handle);
}
示例4: curl_exec_follow
function curl_exec_follow($ch, &$maxredirect = null)
{
// we emulate a browser here since some websites detect
// us as a bot and don't let us do our job
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)" . " Gecko/20041107 Firefox/1.0";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$mr = $maxredirect === null ? 5 : intval($maxredirect);
/* ADDED FALSE HERE */
if (false && filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN) === false && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$newurl = $original_url;
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\\n/i', $header, $matches);
$newurl = trim(array_pop($matches));
// if no scheme is present then the new url is a
// relative path and thus needs some extra care
if (!preg_match("/^https?:/i", $newurl)) {
$newurl = $original_url . $newurl;
}
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
trigger_error('Too many redirects.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
示例5: __construct
public function __construct($url)
{
// make sure the cURL extension is loaded
if (!self::isAvailable()) {
throw new RuntimeException('cURL extension required');
}
if ($url instanceof Curl) {
$this->rHandle = curl_copy_handle($url->rHandle);
} else {
$this->rHandle = curl_init($url);
}
}
示例6: curl_exec_follow
/**
* @see http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/
*
* @param $ch
* @param null $maxredirect
* @return bool|mixed
*/
private function curl_exec_follow($ch, &$maxredirect = null)
{
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$newurl = $original_url;
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\\n/', $header, $matches);
$newurl = trim(array_pop($matches));
// if no scheme is present then the new url is a
// relative path and thus needs some extra care
if (!preg_match("/^https?:/i", $newurl)) {
$newurl = $original_url . $newurl;
}
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
trigger_error('Too many redirects.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
示例7: curl_exec_follow
private function curl_exec_follow($ch, &$maxredirect = null)
{
$user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)" . " Gecko/20041107 Firefox/1.0";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (filter_var(ini_get('open_basedir'), FILTER_VALIDATE_BOOLEAN) === false && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
} else {
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$newurl = $original_url;
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\\n/i', $header, $matches);
$newurl = trim(array_pop($matches));
if (!preg_match("/^https?:/i", $newurl)) {
$newurl = $original_url . $newurl;
}
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
trigger_error('Too many redirects.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
示例8: curlPage
/**
* 利用curl的形式获得页面请求 请用这个函数取代file_get_contents
*/
public static function curlPage($paramArr)
{
if (is_array($paramArr)) {
$options = array('url' => false, 'timeout' => 2, 'recErrLog' => 0, 'reConnect' => 0, 'keepAlive' => 0);
$options = array_merge($options, $paramArr);
extract($options);
}
$timeout = (int) $timeout;
if (0 == $timeout || empty($url)) {
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
#避免首先解析ipv6
}
if ($keepAlive) {
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_HTTPHEADER, array('Connection: Keep-Alive', 'Keep-Alive: 3'));
$data = curl_exec($rch);
} else {
$data = curl_exec($ch);
}
#记录错误日志
if ($recErrLog || $reConnect) {
$errNo = curl_errno($ch);
if ($reConnect && (28 == $errNo || 7 == $errNo || 6 == $errNo)) {
#超时重连 6:name lookup timed out
$errMsg = curl_error($ch);
$data = self::curlPage(array('url' => $url, 'timeout' => 1, 'recErrLog' => 1, 'reConnect' => 0));
#这次不需要重连
#ZOL_Log::write("[api_curl_toreconn][{$url}] [{$errNo}]{$errMsg}", ZOL_Log::TYPE_ERROR);
} elseif ($errNo && $recErrLog) {
#记录错误
$errMsg = curl_error($ch);
#ZOL_Log::write("[api_curl][{$url}] [{$errNo}]" . $errMsg, ZOL_Log::TYPE_ERROR);
}
}
if (!$keepAlive) {
curl_close($ch);
}
return $data;
}
示例9: transactionSearch
/**
* @param array $searchParameters
* @return TransactionSearchResponse[]
* @throws TransactionSearchException
*/
public function transactionSearch(array $searchParameters)
{
$allowedParameters = array("STARTDATE", "ENDDATE", "EMAIL", "RECEIVER", "RECEPITID", "TRANSACTIONID", "INVNUM", "ACCT", "AUCTIONITEMNUMBER", "TRANSACTIONCLASS", "AMT", "CURRENCYCODE", "STATUS", "PROFILEID", "SALUTATION", "FIRSTNAME", "MIDDLENAME", "LASTNAME", "SUFFIX");
$localClient = curl_copy_handle($this->_client);
$url = $this->_config["nvp_endpoint"];
$url .= "?METHOD=TransactionSearch&VERSION=114.0";
$url .= "&USER=" . $this->_config["username"];
$url .= "&PWD=" . $this->_config["password"];
$url .= "&SIGNATURE=" . $this->_config["signature"];
if (count($searchParameters) == 0) {
throw new TransactionSearchException("At least one search parameter must be specified");
}
foreach ($searchParameters as $parameter => $value) {
$parameter = strtoupper($parameter);
if (!in_array($parameter, $allowedParameters)) {
throw new TransactionSearchException("{$parameter} is not a valid search parameter");
}
$url .= "&" . $parameter . "=" . urlencode($value);
}
curl_setopt($localClient, CURLOPT_URL, $url);
$rawResponse = curl_exec($localClient);
$results = array();
$filter = "/^l_([a-z]+)([0-9]+)\$/";
$responseData = explode("&", $rawResponse);
foreach ($responseData as $response) {
$responseValues = explode("=", $response);
if (count($responseValues) < 2) {
continue;
}
$key = strtolower($responseValues[0]);
if ($key == "ack" && $responseValues[1] != "Success") {
$error = new \stdClass();
UrlHelper::urlToObject($rawResponse, $error);
throw new TransactionSearchException("Could not perform search: " . $error->l_shortmessage0 . "(" . $error->l_longmessage0 . ")");
}
$matches = array();
if (preg_match($filter, $key, $matches)) {
$field = $matches[1];
$offset = $matches[2];
if (!isset($results[$offset])) {
$results[$offset] = new TransactionSearchResponse();
}
$results[$offset]->{$field} = urldecode($responseValues[1]);
}
}
return $results;
}
示例10: save
function save($curpass, $passwd)
{
$rcmail = rcmail::get_instance();
if (is_null($curpass)) {
$curpass = $rcmail->decrypt($_SESSION['password']);
}
if ($ch = curl_init()) {
// initial login
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => 'https://ssl.df.eu/chmail.php', CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(array('login' => $rcmail->user->get_username(), 'pwd' => $curpass, 'action' => 'change'))));
if ($result = curl_exec($ch)) {
// login successful, get token!
$postfields = array('pwd1' => $passwd, 'pwd2' => $passwd, 'action[update]' => 'Speichern');
preg_match_all('~<input name="(.+?)" type="hidden" value="(.+?)">~i', $result, $fields);
foreach ($fields[1] as $field_key => $field_name) {
$postfields[$field_name] = $fields[2][$field_key];
}
// change password
$ch = curl_copy_handle($ch);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
if ($result = curl_exec($ch)) {
// has the password been changed?
if (strpos($result, 'Einstellungen erfolgreich') !== false) {
return PASSWORD_SUCCESS;
}
// show error message(s) if possible
if (strpos($result, '<div class="d-msg-text">') !== false) {
preg_match_all('#<div class="d-msg-text">(.*?)</div>#s', $result, $errors);
if (isset($errors[1])) {
$error_message = '';
foreach ($errors[1] as $error) {
$error_message .= trim(mb_convert_encoding($error, 'UTF-8', 'ISO-8859-15')) . ' ';
}
return array('code' => PASSWORD_ERROR, 'message' => $error_message);
}
}
} else {
return PASSWORD_CONNECT_ERROR;
}
} else {
return PASSWORD_CONNECT_ERROR;
}
} else {
return PASSWORD_CONNECT_ERROR;
}
return PASSWORD_ERROR;
}
示例11: curl_exec_follow
function curl_exec_follow($ch, &$maxredirect = null)
{
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($ch, CURLOPT_USERAGENT, "Owncloud Bookmark Crawl");
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\\n/', $header, $matches);
$newurl = trim(array_pop($matches));
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
OCP\Util::writeLog('bookmark', 'Too many redirects. When following redirects, libcurl hit the maximum amount on bookmark', OCP\Util::ERROR);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
示例12: curl_exec_follow
/**
* [curl_exec_follow description] http://us2.php.net/manual/en/function.curl-setopt.php#102121
* @param curl $ch handler
* @param integer $maxredirect hoe many redirects we allow
* @return contents
*/
function curl_exec_follow($ch, $maxredirect = 5)
{
//using normal curl redirect
if (ini_get('open_basedir') == '' and ini_get('safe_mode' == 'Off')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $maxredirect > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $maxredirect);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
if ($maxredirect > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, TRUE);
curl_setopt($rch, CURLOPT_NOBODY, TRUE);
curl_setopt($rch, CURLOPT_FORBID_REUSE, FALSE);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, TRUE);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 or $code == 302) {
preg_match('/Location:(.*?)\\n/', $header, $matches);
$newurl = trim(array_pop($matches));
} else {
$code = 0;
}
}
} while ($code and --$maxredirect);
curl_close($rch);
if (!$maxredirect) {
if ($maxredirect === NULL) {
trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return FALSE;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
$h = curl_getinfo($ch);
return $h;
}
示例13: send
/**
* Sends a request
*
* @param peer.http.HttpRequest request
* @param int timeout default 60
* @param float connecttimeout default 2.0
* @return peer.http.HttpResponse response object
*/
public function send(HttpRequest $request, $timeout = 60, $connecttimeout = 2.0)
{
$curl = curl_copy_handle($this->handle);
curl_setopt($curl, CURLOPT_URL, $request->url->getCanonicalURL());
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestString());
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
if ($this->proxy && !$this->proxy->isExcluded($request->getUrl())) {
curl_setopt($curl, CURLOPT_PROXY, $this->proxy->host);
curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxy->port);
}
$response = curl_exec($curl);
if (FALSE === $response) {
$errno = curl_errno($curl);
$error = curl_error($curl);
curl_close($curl);
throw new IOException(sprintf('%d: %s', $errno, $error));
}
// ensure handle is closed
curl_close($curl);
return new HttpResponse(new MemoryInputStream($response));
}
示例14: requestContentLength
public function requestContentLength()
{
if ($this->downloadsSize === null) {
$chCopy = array();
foreach ($this->channels as $ch) {
$chCopy[] = $ch = curl_copy_handle($ch);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
$this->curlMultiDownload($chCopy);
$this->downloadsSize = 0.0;
foreach ($chCopy as $ch) {
$length = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
if ($length > 0) {
$this->downloadsSize += $length;
}
curl_close($ch);
}
}
return $this->downloadsSize;
}
示例15: send
/**
* Sends a request
*
* @param peer.http.HttpRequest $request
* @param int $timeout default 60
* @param float $connecttimeout default 2.0
* @return peer.http.HttpResponse response object
*/
public function send(HttpRequest $request, $timeout = 60, $connecttimeout = 2.0)
{
$curl = curl_copy_handle($this->handle);
curl_setopt($curl, CURLOPT_URL, $request->url->getCanonicalURL());
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestString());
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
if ($this->proxy && !$this->proxy->excludes()->contains($request->getUrl())) {
curl_setopt($curl, CURLOPT_PROXY, $this->proxy->host());
curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxy->port());
$read = function ($transfer) {
if (preg_match('#^HTTP/[0-9]\\.[0-9] [0-9]{3} .+\\r\\n\\r\\n#', $transfer, $matches)) {
// Strip "HTTP/x.x 200 Connection established" which is followed by
// the real HTTP message: headers and body
return substr($transfer, strlen($matches[0]));
} else {
return $transfer;
}
};
} else {
$read = function ($transfer) {
return $transfer;
};
}
$return = curl_exec($curl);
if (false === $return) {
$errno = curl_errno($curl);
$error = curl_error($curl);
curl_close($curl);
throw new \io\IOException(sprintf('%d: %s', $errno, $error));
}
// ensure handle is closed
curl_close($curl);
$this->cat && $this->cat->info('>>>', $request->getHeaderString());
$response = new HttpResponse(new MemoryInputStream($read($return)), false);
$this->cat && $this->cat->info('<<<', $response->getHeaderString());
return $response;
}