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


PHP Curl::setOpt方法代码示例

本文整理汇总了PHP中Curl::setOpt方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::setOpt方法的具体用法?PHP Curl::setOpt怎么用?PHP Curl::setOpt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Curl的用法示例。


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

示例1: get

 public function get($url_mixed, $data = array())
 {
     if (is_array($url_mixed)) {
         $curl_multi = curl_multi_init();
         $this->_multi_parent = true;
         $this->curls = array();
         foreach ($url_mixed as $url) {
             $curl = new Curl();
             $curl->_multi_child = true;
             $curl->setOpt(CURLOPT_URL, $this->_buildURL($url, $data), $curl->curl);
             $curl->setOpt(CURLOPT_HTTPGET, true);
             $this->_call($this->_before_send, $curl);
             $this->curls[] = $curl;
             $curlm_error_code = curl_multi_add_handle($curl_multi, $curl->curl);
             if (!($curlm_error_code === CURLM_OK)) {
                 //throw new \ErrorException('cURL multi add handle error: ' .curl_multi_strerror($curlm_error_code));
             }
         }
         foreach ($this->curls as $ch) {
             foreach ($this->_options as $key => $value) {
                 $ch->setOpt($key, $value);
             }
         }
         do {
             $status = curl_multi_exec($curl_multi, $active);
         } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
         foreach ($this->curls as $ch) {
             $this->exec($ch);
         }
     } else {
         $this->setopt(CURLOPT_URL, $this->_buildURL($url_mixed, $data));
         $this->setopt(CURLOPT_HTTPGET, true);
         return $this->exec();
     }
 }
开发者ID:AlexBGD,项目名称:DrKaske,代码行数:35,代码来源:Curl.php

示例2: get

 public function get($url_mixed, $data = array())
 {
     if (is_array($url_mixed)) {
         $curl_multi = curl_multi_init();
         $this->multi_parent = true;
         $this->curls = array();
         foreach ($url_mixed as $url) {
             $curl = new Curl();
             $curl->multi_child = true;
             $curl->beforeSend($this->before_send_function);
             $curl->success($this->success_function);
             $curl->error($this->error_function);
             $curl->complete($this->complete_function);
             $curl->base_url = $url;
             $curl->url = $this->buildURL($url, $data);
             $curl->setOpt(CURLOPT_URL, $curl->url, $curl->curl);
             $curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
             $curl->setOpt(CURLOPT_HTTPGET, true);
             $this->curls[] = $curl;
             $curlm_error_code = curl_multi_add_handle($curl_multi, $curl->curl);
             if (!($curlm_error_code === CURLM_OK)) {
                 throw new \ErrorException('cURL multi add handle error: ' . curl_multi_strerror($curlm_error_code));
             }
         }
         foreach ($this->curls as $ch) {
             foreach ($this->options as $key => $value) {
                 $ch->setOpt($key, $value);
             }
         }
         do {
             curl_multi_select($curl_multi);
             $status = curl_multi_exec($curl_multi, $active);
         } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
         while (!($info_array = curl_multi_info_read($curl_multi)) === false) {
             if (!($info_array['msg'] === CURLMSG_DONE)) {
                 continue;
             }
             foreach ($this->curls as $ch) {
                 if ($ch->curl === $info_array['handle']) {
                     $ch->curl_error_code = $info_array['result'];
                     break;
                 }
             }
         }
         foreach ($this->curls as $ch) {
             $this->exec($ch);
         }
     } else {
         $this->base_url = $url_mixed;
         $this->url = $this->buildURL($url_mixed, $data);
         $this->setOpt(CURLOPT_URL, $this->url);
         $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
         $this->setOpt(CURLOPT_HTTPGET, true);
         return $this->exec();
     }
 }
开发者ID:andela-fadebayo,项目名称:paga-demo,代码行数:56,代码来源:curl.php

示例3: process_user

 public function process_user($username, $password, $facility_code)
 {
     $curl = new Curl();
     $response = array();
     //Get Supplier
     $supplier = $this->get_supplier($facility_code);
     if ($supplier == "kemsa") {
         //Use nascop url
         $url = $this->default_url;
         $post = array("email" => $username, "password" => $password);
         $url = $this->default_url . 'sync/user';
         $curl->post($url, $post);
     } else {
         //Use escm url
         $curl->setBasicAuthentication($username, $password);
         $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
         $url = $this->default_url . 'user/' . $username;
         $curl->get($url);
     }
     //Handle Response
     if ($curl->error) {
         $response['error'] = TRUE;
         $response['content'] = array($curl->error_code);
     } else {
         $response['error'] = FALSE;
         $response['content'] = json_decode($curl->response, TRUE);
     }
     return json_encode($response);
 }
开发者ID:OmondiKevin,项目名称:ADT_MTRH,代码行数:29,代码来源:cdrr_logic.php

示例4: testError

 public function testError()
 {
     $this->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
     $this->curl->get('http://1.2.3.4/');
     $this->assertTrue($this->curl->error === TRUE);
     $this->assertTrue($this->curl->curl_error === TRUE);
     $this->assertTrue($this->curl->curl_error_code === CURLE_OPERATION_TIMEOUTED);
 }
开发者ID:php-mod,项目名称:curl,代码行数:8,代码来源:CurlTest.php

示例5: create

 public static function create($apiKey, $endpoint = self::DEFAULT_ENDPOINT, $version = '1.0')
 {
     $curl = new Curl();
     if (strpos($endpoint, 'https') === 0) {
         $curl->setOpt(CURLOPT_CAINFO, __DIR__ . '/resources/cacert.pem');
     }
     $curl->setHeader('X-Auth-Key', $apiKey);
     $curl->setHeader('Content-Type', 'application/json');
     $connector = new Connector($curl, $apiKey, $version, $endpoint);
     $parser = new Parser();
     $errorHandler = new ErrorHandler();
     return new IUcto($connector, $parser, $errorHandler);
 }
开发者ID:iUcto,项目名称:php-sdk,代码行数:13,代码来源:IUctoFactory.php

示例6: array

 static function mapi_get($url_mixed, $data = array(), $debug = false)
 {
     //$debug=true;
     Yii::import('application.vendors.*');
     require_once 'Tp/Curl.class.php';
     $curl = new Curl();
     if (YII_ENV == 'development') {
         $curl->setHeader('Apihandshake', 'yaochufa');
         $curl->setHeader('Referer', 'http://m.yaochufa.com');
     } else {
         $curl->setHeader('Apihandshake', 'yaochufaapi');
         $curl->setHeader('Referer', 'http://m.yaochufa.com');
     }
     $curl->setOpt(CURLOPT_TIMEOUT, 15);
     $data['system'] = Yii::app()->params['mmm_api']['system'];
     $curl->get($url_mixed, $data);
     if ($debug == true) {
         XUtils::dump($curl->request_headers);
     }
     return $curl->response;
 }
开发者ID:mgcxy,项目名称:yiiSwoole,代码行数:21,代码来源:XHttp.php

示例7: addPut

 /**
  * Add Put
  *
  * @access public
  * @param  $url
  * @param  $data
  *
  * @return object
  */
 public function addPut($url, $data = array())
 {
     if (is_array($url)) {
         $data = $url;
         $url = $this->baseUrl;
     }
     $curl = new Curl();
     $curl->setURL($url);
     $curl->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
     $put_data = $curl->buildPostData($data);
     $curl->setHeader('Content-Length', strlen($put_data));
     $curl->setOpt(CURLOPT_POSTFIELDS, $put_data);
     $this->addHandle($curl);
     return $curl;
 }
开发者ID:AlusaChen,项目名称:alusachen.com,代码行数:24,代码来源:MultiCurl.php

示例8: Curl

<?php

// Perform a post-redirect-get request (POST data and follow 303 redirections
// using GET requests).
$curl = new Curl();
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->post('https://www.example.com/login/', array('username' => 'myusername', 'password' => 'mypassword'));
// POST data and follow 303 redirections by POSTing data again. Please note
// that 303 redirections should not be handled this way.
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
$curl = new Curl();
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->post('https://www.example.com/login/', array('username' => 'myusername', 'password' => 'mypassword'), false);
// A POST request performs a post-redirect-get by default. Other request
// methods force an option which conflicts with the post-redirect-get behavior.
// Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not
// possible to reset this option. It is therefore impossible to perform a
// post-redirect-get request using a php-curl-class Curl object that has already
// been used to perform other types of requests. Either use a new php-curl-class
// Curl object or upgrade your PHP engine.
开发者ID:zachborboa,项目名称:php-curl-class,代码行数:20,代码来源:post_redirect_get.php

示例9: array

 function curlNet2($method, $url, $param = array(), $ssl = FALSE)
 {
     require dirname(__FILE__) . '/ext/curl.php';
     $curl = new Curl();
     $exMethod = strtolower($method);
     if ($ssl == TRUE) {
         $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
     }
     $curl->{$exMethod}($url, $param);
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
         $curl->close();
     } else {
         return $curl->response;
         $curl->close();
         unset($curl);
     }
 }
开发者ID:urangawak,项目名称:minangcms,代码行数:18,代码来源:M_net.php

示例10: testRequiredOptionCurlOptReturnTransferEmitsWarning

 /**
  * @expectedException PHPUnit_Framework_Error_Warning
  */
 public function testRequiredOptionCurlOptReturnTransferEmitsWarning()
 {
     $curl = new Curl();
     $curl->setOpt(CURLOPT_RETURNTRANSFER, false);
 }
开发者ID:canerdogan,项目名称:php-curl-class,代码行数:8,代码来源:PHPCurlClassTest.php

示例11: addSearch

 /**
  * Add Search
  *
  * @access public
  * @param  $url
  * @param  $data
  *
  * @return object
  */
 public function addSearch($url, $data = array())
 {
     if (is_array($url)) {
         $data = $url;
         $url = $this->baseUrl;
     }
     $curl = new Curl();
     $curl->setUrl($url);
     $curl->setOpt(CURLOPT_CUSTOMREQUEST, 'SEARCH');
     $put_data = $curl->buildPostData($data);
     if (is_string($put_data)) {
         $curl->setHeader('Content-Length', strlen($put_data));
     }
     $curl->setOpt(CURLOPT_POSTFIELDS, $put_data);
     $this->queueHandle($curl);
     return $curl;
 }
开发者ID:zachborboa,项目名称:php-curl-class,代码行数:26,代码来源:MultiCurl.php

示例12: _connect

    private function _connect($url) {
        $curl = new Curl();
        $curl -> setOpt(CURLOPT_RETURNTRANSFER, TRUE);
        $curl -> setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
        $curl -> get($url);

        if ($curl -> error) {
            $curl -> error_code;
            $response = "Error: " . $curl -> error_code;
        } else {
            $response = $curl -> response;
        }
        return $response;
    }
开发者ID:HCMPKenya,项目名称:hcmp_demo,代码行数:14,代码来源:Github_updater.php

示例13: testErrorCallback

 public function testErrorCallback()
 {
     $success_called = FALSE;
     $error_called = FALSE;
     $complete_called = FALSE;
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
     $curl->success(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $success_called = TRUE;
     });
     $curl->error(function ($instance) use(&$success_called, &$error_called, &$complete_called, &$curl) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $error_called = TRUE;
     });
     $curl->complete(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertTrue($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $complete_called = TRUE;
     });
     $curl->get(Test::ERROR_URL);
     $this->assertFalse($success_called);
     $this->assertTrue($error_called);
     $this->assertTrue($complete_called);
 }
开发者ID:canerdogan,项目名称:php-curl-class,代码行数:36,代码来源:run.php

示例14: Curl

<?php

define('MAX_SIZE', 3 * 1024 * 1024);
require "vendor/autoload.php";
use Respect\Validation\Validator as v;
$url = $_GET['url'];
$url_parts = parse_url($url);
//error_log(print_r($url_parts,1));
// check valid url.
if (!v::arr()->key('scheme', v::startsWith('http'))->key('host', v::domain())->key('path', v::string())->validate($url_parts)) {
    die_and_log($status = 400, 'invalid url', $url);
}
// head access
$c = new Curl();
$c->setHeader('X-Forwarded-For', getRemoteIP());
$c->setOpt(CURLOPT_NOBODY, true);
$c->setOpt(CURLOPT_RETURNTRANSFER, true);
$c->error(function () {
    die_and_log($status = 500, "head request error");
});
$c->get($url);
error_log($url);
//error_log(print_r($c->response_headers,1));
// check head res
$length = null;
$content_type = null;
foreach ($c->response_headers as $header) {
    if (preg_match("/\\AContent-Length/i", $header)) {
        $length = (int) explode(":", $header, 2)[1];
    } else {
        if (preg_match("/\\AContent-Type/i", $header)) {
开发者ID:syossan27,项目名称:JS_LGTM_Editor,代码行数:31,代码来源:proxy.php

示例15: get_updates

 public function get_updates($type = 0)
 {
     if ($type != 0) {
         if ($this->session->userdata("update_timer") != "") {
             $to_time = strtotime(date('Y-m-d H:i:s'));
             $from_time = strtotime($this->session->userdata("update_timer"));
             if (round(abs($to_time - $from_time) / 60, 2) <= 10) {
                 $this->session->set_userdata("update_test", false);
                 echo 2;
                 die;
             }
         }
         $this->session->set_userdata("update_timer", date('Y-m-d H:i:s'));
     }
     ini_set("max_execution_time", "1000000");
     $current_month_start = date('Y-m-01');
     $one_current_month_start = date('Y-m-d', strtotime($current_month_start . "-1 month"));
     $two_current_month_start = date('Y-m-d', strtotime($current_month_start . "-2 months"));
     $three_current_month_start = date('Y-m-d', strtotime($current_month_start . "-3 months"));
     $facility_code = $this->session->userdata('facility');
     $api_userID = $this->session->userdata('api_id');
     $facility_list = User_Facilities::getHydratedFacilityList($api_userID);
     $lists = json_decode($facility_list['facility'], TRUE);
     $facility = Facilities::getSupplier($facility_code);
     $supplier = $facility->supplier->name;
     $links = array();
     $curl = new Curl();
     if (strtoupper($supplier) == "KENYA PHARMA") {
         $url = $this->esm_url;
         foreach ($lists as $facility_id) {
             if ($type == 0) {
                 $links[] = "facility/" . $facility_id . "/cdrr";
                 $links[] = "facility/" . $facility_id . "/maps";
             } else {
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $current_month_start;
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $one_current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $one_current_month_start;
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $two_current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $two_current_month_start;
             }
         }
         $username = $this->session->userdata('api_user');
         $password = $this->session->userdata('api_pass');
         $curl->setBasicAuthentication($username, $password);
         $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
     } else {
         $url = $this->nascop_url;
         if (!empty($lists)) {
             $lists = explode(",", $lists[0]);
             foreach ($lists as $facility_id) {
                 if ($type == 0) {
                     $links[] = "sync/facility/" . $facility_id . "/cdrr";
                     $links[] = "sync/facility/" . $facility_id . "/maps";
                 } else {
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $one_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $one_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $two_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $two_current_month_start;
                 }
             }
         }
     }
     //clear orders if its a full sync
     if ($type == 0) {
         $this->clear_orders();
     }
     foreach ($links as $link) {
         $target_url = $url . $link;
         $curl->get($target_url);
         if ($curl->error) {
             $curl->error_code;
             echo "Error: " . $curl->error_code . "<br/>";
         } else {
             $main_array = json_decode($curl->response, TRUE);
             $clean_data = array();
             foreach ($main_array as $main) {
                 if ($main['code'] == "D-CDRR" || $main['code'] == "F-CDRR_units" || $main['code'] == "F-CDRR_packs") {
                     $type = "cdrr";
                 } else {
                     $type = "maps";
                 }
                 if ($type == 0) {
                     if (is_array($main)) {
                         if (!empty($main)) {
                             $id = $this->extract_order($type, array($main), $main['id']);
                         }
                     }
                 } else {
                     if ($main['period_begin'] == $current_month_start || $main['period_begin'] == $one_current_month_start || $main['period_begin'] == $two_current_month_start) {
                         if (is_array($main)) {
                             if (!empty($main)) {
                                 $id = $this->extract_order($type, array($main), $main['id']);
                             }
                         }
                     }
                 }
             }
//.........这里部分代码省略.........
开发者ID:OmondiKevin,项目名称:ADT_MTRH,代码行数:101,代码来源:order.php


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