Ejemplo n.º 1
0
 public function downloadFile($token, \proto\DownloadParam $param)
 {
     $filename = $param->objid;
     $offer_set = $param->offerset;
     $buf_size = $param->reqlen;
     $token_c = new \lib\Token_Core();
     $h_ret = array('ret' => 4, 'msg' => 'download file [' . $filename . '] token invalid!');
     if ($token_c->is_token($token)) {
         if (APP_DEBUG) {
             $starttime = microtime();
             //               file_put_contents('/var/log/nginx/chdserver.log', $token.'|downloadFile|'.PHP_EOL, FILE_APPEND | LOCK_EX);
             //               file_put_contents('/var/log/nginx/chdserver.log', ''.$starttime.'|downloadFile|start|'.PHP_EOL, FILE_APPEND | LOCK_EX);
         }
         $Bucket_name = self::_get_bucket_name_by_ftype($param->type);
         $host = CEPH_HOST;
         $aws_key = session('user_key');
         $aws_secret_key = session('user_secret_key');
         $conn = new cephService($host, $aws_key, $aws_secret_key);
         $ret = $conn->downloadFile($Bucket_name, $filename, $offer_set, $buf_size);
         if ($ret['status'] != 0) {
             $h_ret = array('ret' => $ret['status'], 'msg' => $ret['msg']);
         } else {
             $h_ret = array('ret' => $ret['status'], 'msg' => 'download File [' . $filename . '] successfully');
         }
     }
     $ret_h = new \proto\RetHead($h_ret);
     $ret_arr = array('result' => $ret_h, 'bin' => $ret['status'] == 0 ? $ret['msg'] : '');
     $ret_d = new DownloadResult($ret_arr);
     if (APP_DEBUG) {
         file_put_contents('/var/log/nginx/chdserver.log', '' . microtime() - $starttime . '|downloadFile|end|' . PHP_EOL, FILE_APPEND | LOCK_EX);
     }
     return $ret_d;
 }