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


PHP Curl::success方法代码示例

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


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

示例2: 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


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