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


PHP HttpClient::get_body方法代码示例

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


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

示例1: checkNodeStatus

 /**
  * 检查存储节点状态
  * @param string $host
  * @return int
  */
 public function checkNodeStatus($host)
 {
     $url = $host . '/api.php';
     $data = array('route' => "store/status", 'callback_url' => PluginMiniStoreOption::getInstance()->getMiniyunHost() . "info.htm");
     $http = new HttpClient();
     $http->post($url, $data);
     $result = $http->get_body();
     $result = @json_decode($result, true);
     if ($result["status"] == "1") {
         return 1;
     }
     return -1;
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:18,代码来源:PluginMiniStoreNode.php

示例2: pushFileConvert

 /**
  * 把文档进行转换
  * @param array $version
  * @param string $mimeType 如mineType为空,则使用version.mime_type
  */
 private function pushFileConvert($version, $mimeType)
 {
     if (empty($mimeType)) {
         $mimeType = $version["mime_type"];
     }
     $miniHost = PluginMiniDocOption::getInstance()->getMiniyunHost();
     $siteId = MiniSiteUtils::getSiteID();
     $signature = $version["file_signature"];
     $node = PluginMiniDocNode::getInstance()->getConvertNode($signature);
     if (!empty($node)) {
         $url = $node["host"] . '/api.php?route=file/convert';
         $downloadUrl = $miniHost . "api.php?route=module/miniDoc/download&signature=" . $signature;
         $callbackUrl = $miniHost . "api.php?route=module/miniDoc/report&node_id=" . $node["id"] . "&signature=" . $signature;
         $data = array('signature' => $signature, 'site_id' => $siteId, 'mime_type' => $mimeType, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
         $http = new HttpClient();
         $http->post($url, $data);
         $result = $http->get_body();
         $result = json_decode($result, true);
         if ($result['status'] == 1) {
             $this->updateDocConvertStatus($node["id"], $version["file_signature"], 1);
         }
     }
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:28,代码来源:PluginMiniDocVersion.php

示例3: searchKeyWordAndSiteId

 /**
  * 根据关键字+SiteId向迷你搜索发送请求
  * @param string $key 关键字
  * @param string $siteId 站点ID
  * @return array 返回signature列表
  */
 private function searchKeyWordAndSiteId($siteId, $key)
 {
     $opts = array("before_match" => "<span style='background-color: #ffff00'><b>", "after_match" => "</b></span>", "chunk_separator" => " ... ", "limit" => 150, "around" => 75);
     //向迷你搜索服务器发送搜索请求
     $node = PluginMiniSearchNode::getInstance()->getBestNode();
     if (!empty($node)) {
         $url = $node["host"] . '/api.php';
         $data = array('route' => "file/search", 'site_id' => $siteId, 'key' => $key);
         foreach ($opts as $key => $value) {
             $data[$key] = $value;
         }
         $http = new HttpClient();
         $http->post($url, $data);
         $body = $http->get_body();
         $body = json_decode($body, true);
         if ($body['status'] == 1) {
             PluginMiniSearchNode::getInstance()->newSearch($node["id"]);
             return $body["result"];
         }
     }
     return array();
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:28,代码来源:PluginMiniSearchBiz.php

示例4: pushReplicateTask

 /**
  * 推送任务到文件冗余备份服务器
  * @param $miniHost
  * @param $task
  */
 private function pushReplicateTask($miniHost, $task)
 {
     $node = PluginMiniStoreNode::getInstance()->getNodeById($task->node_id);
     //如目标服务器不可用,则不用发送请求
     if ($node["status"] == 1) {
         $signature = $task->file_signature;
         $version = MiniVersion::getInstance()->getBySignature($signature);
         $downloadUrl = $miniHost . "api.php?route=module/miniStore/download&signature=" . $signature;
         $callbackUrl = $miniHost . "api.php?route=module/miniStore/replicateReport&signature=" . $signature . "&node_id=" . $node["id"];
         //向迷你存储发送冗余备份请求
         $data = array('route' => "file/replicate", 'size' => $version["file_size"], 'signature' => $signature, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
         $http = new HttpClient();
         $http->post($node["host"] . "/api.php", $data);
         $content = $http->get_body();
         if (!empty($content)) {
             $status = @json_decode($content)->{"status"};
             if ($status == 1) {
                 //目标服务器接受请求后,更改任务状态
                 $task->status = 1;
                 $task->save();
             }
         }
     }
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:29,代码来源:PluginMiniReplicateTask.php

示例5: buildTask

 /**
  * 编制索引
  * @param $miniHost
  * @param $siteId
  * @param $task
  */
 private function buildTask($miniHost, $siteId, $task)
 {
     $nodeId = $task->node_id;
     $signature = $task->file_signature;
     $node = PluginMiniSearchNode::getInstance()->getNodeById($nodeId);
     if (!empty($node)) {
         $url = $node["host"] . '/api.php?route=file/build';
         $downloadUrl = $miniHost . "api.php?route=module/miniSearch/downloadTxt&signature=" . $signature;
         $callbackUrl = $miniHost . "api.php?route=module/miniSearch/report&node_id=" . $node["id"] . "&signature=" . $signature;
         $data = array('signature' => $signature, 'site_id' => $siteId, 'download_url' => $downloadUrl, "callback_url" => $callbackUrl);
         $http = new HttpClient();
         $http->post($url, $data);
         $result = $http->get_body();
         $result = @json_decode($result, true);
         if ($result['status'] == 1) {
             //修改task状态
             $task->status = 1;
             $task->save();
         }
     }
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:27,代码来源:PluginMiniSearchBuildTask.php

示例6: previewContent

 /**
  * 在线浏览文件获得内容
  * @param string $path 文件当前路径
  * @param string $type 文件类型,可选择pdf/png
  * @throws
  * @return NULL
  */
 public function previewContent($path, $type)
 {
     $file = MiniFile::getInstance()->getByPath($path);
     // 权限处理
     if (empty($file)) {
         return array('success' => false, 'msg' => 'file not existed');
     }
     $fileBiz = new FileBiz();
     $canRead = $fileBiz->privilege($path);
     if (!$canRead) {
         throw new MFileopsException(Yii::t('api', 'no permission'), MConst::HTTP_CODE_409);
     }
     //获得文件当前版本对应的version
     $version = PluginMiniDocVersion::getInstance()->getVersion($file["version_id"]);
     $signature = $version["file_signature"];
     $localPath = PluginMiniDocOption::getInstance()->getMiniDocCachePath() . $signature . "/" . $signature . "." . $type;
     if (!file_exists($localPath)) {
         //文档还在转换中
         $node = PluginMiniDocNode::getInstance()->getConvertNode($signature);
         if (empty($node)) {
             throw new MFileopsException(Yii::t('api', 'convert error'), MConst::HTTP_CODE_412);
         }
         //根据情况判断是否需要向迷你文档拉取内容
         $parentPath = dirname($localPath);
         //如果缓存目录不存在,则需要创建
         if (!file_exists($parentPath)) {
             MUtils::MkDirsLocal($parentPath);
         }
         //文件不存在,则需要从迷你文档拉取文件内容
         $url = PluginMiniDocNode::getInstance()->getDownloadUrl($node["id"], $version, $type);
         $http = new HttpClient();
         $http->get($url);
         $status = $http->get_status();
         if ($status == "200") {
             $content = $http->get_body();
             //把文件内容存储到本地硬盘
             file_put_contents($localPath, $content);
             Yii::log($signature . " get " . $type . " success", CLogger::LEVEL_INFO, "doc.convert");
         } else {
             if (!($version["doc_convert_status"] == -1)) {
                 //如迷你文档服务器不存在该文档,说明迷你文档服务器发生了变动
                 //这个时候自动启动负载均衡机制,把文档重新转换
                 PluginMiniDocVersion::getInstance()->pushConvertSignature($signature, "");
                 Yii::log($signature . " get " . $type . " error", CLogger::LEVEL_ERROR, "doc.convert");
             }
         }
     }
     if (file_exists($localPath)) {
         if ($type === "png") {
             $contentType = "image/png";
         }
         if ($type === "pdf") {
             $contentType = "Content-type: application/pdf";
         }
         //Firefox+混合云模式下直接输出内容
         //其它浏览器使用sendfile模式输出内容
         $isSendFile = true;
         if (MiniUtil::isMixCloudVersion()) {
             $ua = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : NULL;
             if (strpos($ua, "Firefox") > 0 || strpos($ua, "Safari") > 0) {
                 $isSendFile = false;
             }
         }
         if ($isSendFile) {
             header('Location: ' . MiniHttp::getMiniHost() . "assets/minidoc/" . $signature . "/" . $signature . "." . $type);
         } else {
             Header("Content-type: " . $contentType);
             echo file_get_contents($localPath);
             exit;
         }
     }
 }
开发者ID:youngsun45,项目名称:miniyun,代码行数:79,代码来源:PluginMiniDocBiz.php


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