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


PHP HttpClient::factory方法代码示例

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


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

示例1: driver

 /**
  * HttpClient对象
  * @return HttpClient
  */
 public function driver()
 {
     if (null === $this->_driver) {
         $this->_driver = \HttpClient::factory();
     }
     return $this->_driver;
 }
开发者ID:google2013,项目名称:myqee,代码行数:11,代码来源:rest.class.php

示例2: get_data

 protected function get_data($url)
 {
     $rs = \HttpClient::factory()->get($this->base_url . $url . '?v=' . \Core::VERSION);
     if (200 == $rs->code()) {
         echo $rs->data();
     } else {
         echo '<div style="padding:6px;">请求数据失败,请稍后再试</div>';
         if (\IS_DEBUG) {
             echo '<br>code:' . $rs->code();
             echo '<br><br>' . $rs->data();
         }
     }
 }
开发者ID:google2013,项目名称:myqee,代码行数:13,代码来源:apps.controller.php

示例3: geta

 public static function geta()
 {
     $uri = 'http://tq.21004.com/';
     $data = iconv('GBK', 'UTF-8', \HttpClient::factory()->get($uri)->data());
     $d = array();
     if (preg_match_all('#<h3>([^<]+)</h3>(.*)<\\/div>#Uis', $data, $m)) {
         foreach ($m[0] as $k => $v) {
             $d[$m[1][$k]] = array();
             preg_match_all('#target="_blank">([^<]+)<\\/a>#Uis', $m[2][$k], $m2);
             foreach ($m2[0] as $k2 => $v2) {
                 $d[$m[1][$k]][\PinYin::get($m2[1][$k2])] = $m2[1][$k2];
             }
         }
     }
 }
开发者ID:google2013,项目名称:myqee,代码行数:15,代码来源:weather.class.php

示例4: foreach

 /**
  * 获取当前类型的数据
  *
  * @param OOP_ORM_Data $obj
  * @param $data
  * @param $compiled_data
  * @return mixed
  */
 public function &get_data(OOP_ORM_Data $obj, &$data, &$compiled_data, &$compiled_raw_data)
 {
     # 处理URL变量
     $this->url = $this->config['resource'];
     if (preg_match_all('#{{([a-z0-9_]+)}}#i', $this->url, $m)) {
         foreach ($m[1] as $v) {
             $this->url = str_replace('{{' . $v . '}}', $obj->{$v}, $this->url);
         }
     }
     # 获取缓存
     if (isset($this->config['cache'])) {
         /**
          * @var $cache Cache
          */
         list($cache, $key) = $this->get_cache_instance_and_key($obj);
         $tmp_data = $cache->get($key);
     } else {
         $tmp_data = null;
     }
     # 获取内容
     if (null === $tmp_data || false === $tmp_data) {
         $tmp_data = HttpClient::factory()->get($this->url)->data();
         if (false === $tmp_data) {
             return false;
         }
         # 处理数据类型
         if (isset($this->config['field_type'])) {
             OOP_ORM_DI::_check_field_type($this->config['field_type'], $tmp_data);
         }
         # 设置缓存
         if (isset($this->config['cache'])) {
             $cache->set($key, $tmp_data, isset($this->config['cache']['expired']) ? $this->config['cache']['expired'] : 3600, isset($this->config['cache']['expire_type']) ? $this->config['cache']['expire_type'] : null);
         }
     }
     # 处理格式化数据
     if (isset($this->config['format'])) {
         OOP_ORM_DI::_do_de_format_data($this->config['format'], $tmp_data);
     }
     $compiled_data[$this->key] = $tmp_data;
     $compiled_raw_data[$this->key] = $tmp_data;
     return $compiled_data[$this->key];
 }
开发者ID:xiaodin1,项目名称:myqee,代码行数:50,代码来源:resource.class.php

示例5: action_default

 /**
  * 管理页面首页控制器
  */
 public function action_default()
 {
     $id = $this->arguments[0];
     if (!$id) {
         $this->show_error('缺少参数');
     }
     # APP URL
     $url = $this->base_url . 'get_app_info?id=' . $id;
     /*
     # 获取APP信息
     $data = \HttpClient::factory()->get($url)->data();
     
     $data = @\unserialize($data);
     */
     $data = array('title' => '测试', 'url' => 'http://myqee.com/app_test/Archive.zip', 'type' => 'plug-in', 'hash' => 'd7646fa39b991f02f99251a477dd3ee2');
     $file_dat = \HttpClient::factory()->get($data['url'])->data();
     # 保存文件
     \file_put_contents(\DIR_TEMP . $data['hash'], $file_dat);
     echo 'ok';
 }
开发者ID:google2013,项目名称:myqee,代码行数:23,代码来源:install.controller.php

示例6: _get_data_httpget

 /**
  * 获取HttpClient配置类型的数据
  *
  * @param array $config
  * @return array
  */
 protected static function _get_data_httpget($config)
 {
     if (isset($config['method']) && \strtolower($config['method']) == 'post') {
         $method = 'post';
     } else {
         $method = 'get';
     }
     if (isset($config['type'])) {
         $httpget = \HttpClient::factory($config['type']);
     } else {
         $httpget = \HttpClient::factory();
     }
     if ($method == 'post') {
         if (isset($config['timeout'])) {
             return $httpget->post($config['url'], $config['arguments'], $config['timeout']);
         } else {
             return $httpget->post($config['url'], $config['arguments']);
         }
     } else {
         $config['url'] .= (\strpos($config['url'], '?') ? '&' : '?') . \http_build_query($config['arguments'], '', '&');
         if (isset($config['timeout'])) {
             return $httpget->get($config['url'], $config['timeout']);
         } else {
             return $httpget->get($config['url']);
         }
     }
 }
开发者ID:google2013,项目名称:myqee,代码行数:33,代码来源:parse.class.php

示例7: run

 /**
  * 执行当前任务
  *
  * @return bool|array
  */
 public function run()
 {
     if ($this->accept()) {
         // 获取执行
         try {
             $callback = $this->job['callback'];
             $arguments = $this->job['arguments'];
             if (substr($callback, 0, 7) === 'http://' || substr($callback, 0, 7) === 'https://') {
                 # url
                 if ($arguments) {
                     $query = http_build_query($arguments, '', '&');
                     if (strpos($callback, '?') !== false) {
                         $url = $callback . '&' . $query;
                     } else {
                         $url = $callback . '?' . $query;
                     }
                 } else {
                     $url = $callback;
                 }
                 $rs = HttpClient::factory()->get($url);
                 if ($rs->code() === 200) {
                     $rs = $rs->data();
                 } else {
                     throw new Exception('queue fail. url:' . $url);
                 }
             } elseif (strpos($callback, '::') === false) {
                 # exec
                 $callback = escapeshellcmd($callback);
                 if ($arguments) {
                     $p = '';
                     foreach ((array) $arguments as $item) {
                         $p .= ' ' . escapeshellarg($item);
                     }
                     $callback .= $p;
                 }
                 $rs = trim(shell_exec($callback));
                 $pos = strrpos($rs, "\n");
                 if (false === $pos) {
                     $pos = strrpos($rs, "\r");
                 }
                 if (false === $pos) {
                     $rs2 = $rs;
                 } else {
                     $rs2 = substr($rs, $pos);
                 }
                 if ($rs2 !== 'success') {
                     throw new Exception('queue callback not success. cmd: ' . $callback);
                 }
             } else {
                 $rs = call_user_func($callback, $arguments, $this);
                 if (false === $rs) {
                     throw new Exception('queue callback get false');
                 }
             }
             // 更新状态
             $value = array('status' => Queue::COMPLETE, 'result' => (string) $rs);
             $where = array('id' => $this->id());
             Queue::driver()->update(Queue::$table_name, $value, $where);
             $this->job['result'] = (string) $rs;
             $this->job['status'] = Queue::COMPLETE;
             return true;
         } catch (Exception $e) {
             // 更新状态
             $delay = 10;
             $value = array('job_time' => time() + $delay, 'status' => Queue::RETRY);
             $where = array('id' => $this->id());
             Queue::driver()->value_increment('retry_count', 1)->update(Queue::$table_name, $value, $where);
             throw $e;
         }
     } else {
         return false;
     }
 }
开发者ID:xiaodin1,项目名称:myqee,代码行数:78,代码来源:queue.class.php


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