当前位置: 首页>>代码示例>>PHP>>正文


PHP curl_reset函数代码示例

本文整理汇总了PHP中curl_reset函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_reset函数的具体用法?PHP curl_reset怎么用?PHP curl_reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_reset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: reset

 /**
  * revert all ::setopt() operation
  *
  * @return $this
  */
 public function reset()
 {
     if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
         curl_reset($this->_curl);
     }
     return $this;
 }
开发者ID:TF-Joynic,项目名称:Hydrogen,代码行数:12,代码来源:Curl.php

示例2: curlPrepare

 public static function curlPrepare($url, $options = false)
 {
     if (empty(self::$curl)) {
         self::$curl = curl_init($url);
     } else {
         if (function_exists('curl_reset')) {
             curl_reset(self::$curl);
         } else {
             curl_close(self::$curl);
             self::$curl = null;
             self::$curl = curl_init($url);
         }
     }
     curl_setopt(self::$curl, CURLOPT_HEADER, false);
     curl_setopt(self::$curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt(self::$curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt(self::$curl, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt(self::$curl, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt(self::$curl, CURLOPT_MAXREDIRS, 5);
     curl_setopt(self::$curl, CURLOPT_ENCODING, '');
     curl_setopt(self::$curl, CURLOPT_USERAGENT, 'Curl');
     if ($url) {
         $url = str_ireplace(' ', '%20', $url);
         curl_setopt(self::$curl, CURLOPT_URL, $url);
     }
     if (!empty($options) && is_array($options)) {
         foreach ($options as $option => $value) {
             curl_setopt(self::$curl, $option, $value);
         }
     }
     return self::$curl;
 }
开发者ID:swayok,项目名称:utils,代码行数:32,代码来源:Curl.php

示例3: call

 public function call($uri, $method = 'GET', $content = null)
 {
     $url = $this->getServer() . '/' . ltrim($uri, '/');
     curl_reset($this->_handle);
     curl_setopt($this->_handle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_handle, CURLOPT_HEADER, 1);
     curl_setopt($this->_handle, CURLOPT_URL, $url);
     curl_setopt($this->_handle, CURLOPT_USERAGENT, self::USERAGENT);
     curl_setopt($this->_handle, CURLOPT_CONNECTTIMEOUT, self::CONNECTTIMEOUT);
     curl_setopt($this->_handle, CURLOPT_TIMEOUT, self::TIMEOUT);
     curl_setopt($this->_handle, CURLOPT_SSL_VERIFYPEER, $this->_verifypeer);
     curl_setopt($this->_handle, CURLOPT_COOKIEFILE, '');
     curl_setopt($this->_handle, CURLINFO_HEADER_OUT, true);
     if ($method == 'GET') {
         curl_setopt($this->_handle, CURLOPT_HTTPGET, 1);
     } elseif ($method == 'POST') {
         curl_setopt($this->_handle, CURLOPT_POST, 1);
         curl_setopt($this->_handle, CURLOPT_POSTFIELDS, $content);
     } elseif ($method == 'PUT') {
         curl_setopt($this->_handle, CURLOPT_PUT, 1);
         curl_setopt($this->_handle, CURLOPT_INFILE, $content);
         curl_setopt($this->_handle, CURLOPT_INFILESIZE, filesize($content));
     } else {
         return false;
     }
     $res = curl_exec($this->_handle);
     if ($res === false) {
         return false;
     }
     $data = array('url' => curl_getinfo($this->_handle, CURLINFO_EFFECTIVE_URL), 'http_code' => curl_getinfo($this->_handle, CURLINFO_HTTP_CODE), 'total_time' => curl_getinfo($this->_handle, CURLINFO_TOTAL_TIME), 'request_header' => explode("\r\n", curl_getinfo($this->_handle, CURLINFO_HEADER_OUT)), 'header' => explode("\r\n", substr($res, 0, curl_getinfo($this->_handle, CURLINFO_HEADER_SIZE))), 'body' => substr($res, curl_getinfo($this->_handle, CURLINFO_HEADER_SIZE)));
     return $data;
 }
开发者ID:linearregression,项目名称:redports,代码行数:32,代码来源:ConnectionManager.php

示例4: sendRequest

 /**
  * Execute the request
  * @return [type]
  */
 private function sendRequest()
 {
     $output = curl_exec($this->handle);
     curl_reset($this->handle);
     // clear options
     $this->options = [];
     return $output;
 }
开发者ID:phpanos,项目名称:github-api-php,代码行数:12,代码来源:HttpClient.php

示例5: sendInternal

 protected function sendInternal(CurlConfig $config, $startTime = null, $retryCount = 1)
 {
     if (empty($config->url)) {
         throw new InvalidConfigException("You can't send a request without setting the url first.");
     }
     if ($startTime === null) {
         $startTime = time();
     }
     if (!is_resource($this->handle)) {
         $this->handle = curl_init();
     } else {
         curl_reset($this->handle);
     }
     if (!empty($config->cookies)) {
         curl_setopt($this->handle, CURLOPT_COOKIE, http_build_query($config->cookies, '', '; ', PHP_QUERY_RFC3986));
     }
     if (!empty($config->headers)) {
         $headers = [];
         foreach ($config->headers as $name => $value) {
             $headers[] = "{$name}: {$value}";
         }
         curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers);
     }
     if (!empty($config->referer)) {
         curl_setopt($this->handle, CURLOPT_REFERER, $config->referer);
     }
     curl_setopt_array($this->handle, [CURLOPT_ENCODING => 'gzip,deflate', CURLOPT_URL => $config->url, CURLOPT_POST => $config->method === self::METHOD_POST, CURLOPT_USERAGENT => $config->userAgent, CURLOPT_AUTOREFERER => $config->autoReferer, CURLOPT_FOLLOWLOCATION => $config->followRedirects, CURLOPT_MAXREDIRS => $config->maxRedirects, CURLOPT_CONNECTTIMEOUT => (int) $config->connectTimeout, CURLOPT_TIMEOUT => (int) $config->globalTimeout, CURLOPT_HEADER => true, CURLOPT_NOBODY => $config->headersOnly, CURLOPT_RETURNTRANSFER => true, CURLOPT_FORBID_REUSE => !$config->reuseConnection, CURLOPT_MAX_RECV_SPEED_LARGE => $config->maxReceiveSpeed, CURLOPT_MAX_SEND_SPEED_LARGE => $config->maxSendSpeed, CURLOPT_LOW_SPEED_LIMIT => $config->lowSpeedLimit, CURLOPT_LOW_SPEED_TIME => $config->lowSpeedTime, CURLOPT_SSL_VERIFYHOST => $config->sslVerifyHost, CURLOPT_SSL_VERIFYPEER => $config->sslVerifyPeer, CURLOPT_FAILONERROR => false, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS]);
     if ($config->proxy !== null) {
         $proxy = $config->getProxyInfo();
         curl_setopt_array($this->handle, [CURLOPT_PROXY => $proxy['ip'], CURLOPT_PROXYPORT => $proxy['port'], CURLOPT_PROXYTYPE => $proxy['type'], CURLOPT_PROXYUSERPWD => $proxy['login']]);
     }
     if ($config->progressHandler !== null && !$config->headersOnly) {
         curl_setopt_array($this->handle, [CURLOPT_NOPROGRESS => false, CURLOPT_PROGRESSFUNCTION => function ($curl, $dltotal, $dlnow, $ultotal, $ulnow) use($config) {
             return call_user_func_array($config->progressHandler, [$dltotal, $dlnow, $ultotal, $ulnow]);
         }]);
     }
     $response = new CurlResponse($this->handle, clone $config, curl_exec($this->handle));
     if ($response->getFailed()) {
         if ($config->throwException && $response->getTooManyRedirects()) {
             throw new TooManyRedirectsException($response, "The request failed due to too many redirects.", $response->errorNumber);
         } elseif ($config->throwException && $response->aborted) {
             throw new RequestAbortedException($response, "The request was aborted.", $response->errorNumber);
         } elseif ($config->retryHandler !== null && call_user_func_array($config->retryHandler, [$config, $response, $retryCount, time() - $startTime])) {
             $this->sendInternal($config, $startTime, ++$retryCount);
         } elseif ($config->throwException) {
             if ($response->getTimedOut()) {
                 throw new RequestTimedOutException($response, "The request timed out.", $response->errorNumber);
             } else {
                 throw new RequestFailedException($response, sprintf("The request failed: %s (#%d)", $response->error, $response->errorNumber), $response->errorNumber);
             }
         }
     } elseif (!empty($config->expectedHttpCodes) && !in_array($response->getHttpCode(), $config->expectedHttpCodes)) {
         throw new UnexpectedHttpCodeException($response, "Received an unexpected http code: {$response->getHttpCode()}", $response->errorNumber);
     }
     return $response;
 }
开发者ID:kidol,项目名称:curl,代码行数:56,代码来源:CurlRequest.php

示例6: curl_reset_handle

/** \brief Reset cURL handle and set default options.
 *
 * \return Returns nothing on success. Otherwise an error message will be
 *  displayed and PHP dies.
 */
function curl_reset_handle($curl_handle)
{
    // reset cURL handle
    curl_reset($curl_handle);
    // enable cookie engine
    $options = array(CURLOPT_COOKIESESSION => true, CURLOPT_COOKIEJAR => "/dev/null");
    if (!curl_setopt_array($curl_handle, $options)) {
        error(500, "cURL Cookie-engine konnte nicht initialisiert werden.");
    }
}
开发者ID:alehaa,项目名称:cocal,代码行数:15,代码来源:calendar.php

示例7: resetResourceOptions

 protected function resetResourceOptions()
 {
     if (PHP_VERSION >= 5.5 && \function_exists('curl_reset')) {
         \curl_reset($this->curlResource);
     } else {
         \curl_close($this->curlResource);
         $this->curlResource = \curl_init();
     }
     return $this;
 }
开发者ID:dypa,项目名称:phpmulticurl,代码行数:10,代码来源:CurlThread.php

示例8: release

 public function release(EasyHandle $easy)
 {
     $resource = $easy->handle;
     unset($easy->handle);
     if (count($this->handles) >= $this->maxHandles) {
         curl_close($resource);
     } else {
         curl_reset($resource);
         $this->handles[] = $resource;
     }
 }
开发者ID:alvarobfdev,项目名称:LaravelCore,代码行数:11,代码来源:CurlFactory.php

示例9: GetCurl

 private static function GetCurl()
 {
     static $registeredShutdown = false;
     if (is_null(static::$curl_handle)) {
         static::$curl_handle = curl_init();
     } else {
         curl_reset(static::$curl_handle);
     }
     if (!$registeredShutdown) {
         $registeredShutdown = true;
         register_shutdown_function([HTTP::class, 'CloseCurl']);
     }
     return static::$curl_handle;
 }
开发者ID:erorus,项目名称:newsstand,代码行数:14,代码来源:NewsstandHTTP.incl.php

示例10: request

 public function request(RequestInterface $request)
 {
     if (is_resource($this->handler)) {
         curl_reset($this->handler);
     } else {
         $this->handler = curl_init();
     }
     $options = $this->createRequestOptions($request);
     foreach ($options as $option => $value) {
         curl_setopt($this->handler, $option, $value);
     }
     $raw = curl_exec($this->handler);
     if (curl_errno($this->handler) > 0) {
         throw new CurlException(curl_errno($this->handler), curl_error($this->handler), $request);
     } else {
         return $raw;
     }
 }
开发者ID:serp-spider,项目名称:http-client-curl,代码行数:18,代码来源:Curl.php

示例11: release

 public function release(EasyHandle $easy)
 {
     $resource = $easy->handle;
     unset($easy->handle);
     if (count($this->handles) >= $this->maxHandles) {
         curl_close($resource);
     } else {
         // Remove all callback functions as they can hold onto references
         // and are not cleaned up by curl_reset. Using curl_setopt_array
         // does not work for some reason, so removing each one
         // individually.
         curl_setopt($resource, CURLOPT_HEADERFUNCTION, null);
         curl_setopt($resource, CURLOPT_READFUNCTION, null);
         curl_setopt($resource, CURLOPT_WRITEFUNCTION, null);
         curl_setopt($resource, CURLOPT_PROGRESSFUNCTION, null);
         curl_reset($resource);
         $this->handles[] = $resource;
     }
 }
开发者ID:nazo,项目名称:guzzle,代码行数:19,代码来源:CurlFactory.php

示例12: post

 /**
  * POST form, returning contents
  * @param string $url
  * @opt_param string|array $data
  * @opt_param bool $debug
  * @return string $html
  */
 public function post($url, $data = false, $debug = false)
 {
     $ch = curl_init();
     curl_reset($ch);
     curl_setopt($ch, CURLOPT_URL, $url);
     if (preg_match("/^https/", $url)) {
         curl_setopt($ch, CURLOPT_PORT, 443);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     }
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_NOBODY, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     $headers = array();
     foreach ($this->headers as $key => $value) {
         $headers[] = $key . ": " . $value;
     }
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     // dEBUGGING ...
     if ($debug) {
         $fh = fopen('postdebug.log', 'a');
         curl_setopt($ch, CURLOPT_VERBOSE, $debug);
         curl_setopt($ch, CURLOPT_STDERR, $fh);
     }
     $response = curl_exec($ch);
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header_string = substr($response, 0, $header_size);
     $body = substr($response, $header_size);
     $this->response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if (curl_errno($ch)) {
         throw new CurlException("Curl error on {$url}: " . curl_error($ch));
     } else {
         return $body;
     }
 }
开发者ID:stevepatter,项目名称:useful-scripts,代码行数:45,代码来源:Curl.php

示例13: downloadCurl

 public function downloadCurl($url, $fresh_connect = false)
 {
     if (!function_exists('curl_init')) {
         die('cURL is not installed');
     }
     $ch = curl_init();
     if ($fresh_connect) {
         curl_reset($ch);
         curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
         curl_setopt($ch, CURL_FORBID_REUSE, 1);
     }
     curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
     curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_ENCODING, "UTF-8");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     $output = curl_exec($ch);
     curl_close($ch);
     return $output;
 }
开发者ID:Gatzzu,项目名称:test,代码行数:23,代码来源:Scrap.php

示例14: reset

 /**
  * @return void
  */
 public function reset()
 {
     $this->handle && curl_reset($this->handle);
 }
开发者ID:vitalsaude,项目名称:api,代码行数:7,代码来源:Curl55.php

示例15: reset

 /**
  * Reset all options of a libcurl session handle
  *
  * @author Art <a.molcanovas@gmail.com>
  * @return Curl
  * @link   http://php.net/manual/en/function.curl-reset.php
  */
 function reset()
 {
     Log::debug('Reset Curl');
     curl_reset($this->ch);
     curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
     return $this;
 }
开发者ID:alorel,项目名称:alo-framework,代码行数:14,代码来源:curl.php


注:本文中的curl_reset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。