OSS\OssClient::setConnectTimeout PHP Метод

setConnectTimeout() публичный Метод

设置http库的连接超时时间,单位秒
public setConnectTimeout ( integer $connectTimeout )
$connectTimeout integer
    public function setConnectTimeout($connectTimeout)
    {
        $this->connectTimeout = $connectTimeout;
    }

Usage Example

Пример #1
0
 /**
  * 当个上传文件并返回上传的URL地址
  * @param $filename string 要保存的文件名称 注意如果存在目录的话
  * @param $filepath string 文件在服务器(本地的绝对或者相对路径,这里的服务器实际上是本地)上的路径
  * @return bool or url
  */
 public function upload2AliyunSdkSingle($filename, $filepath)
 {
     $dir = C('ALIYUN_DIR');
     //保存在阿里云的基本路径
     $endpoint = C('ALIYUN_endpoint');
     //阿里云的节点信息 请自行查阅本字段意义
     $midStr = 'upload/' . date('y') . '/' . date('m') . '/' . date('d') . '/';
     //这里是为了保存的路径暂时以当前时间为准
     try {
         $ossClient = new OssClient(C('ALIYUN_KeyId'), C('ALIYUN_KeySecret'), $endpoint);
         //这里要放入你从阿里云获得的key和secret这里我做成了配置项读取
     } catch (OssException $e) {
         print $e->getErrorMessage();
     }
     $ossClient->setTimeout(3600);
     // 设置请求超时时间
     $ossClient->setConnectTimeout(10);
     //设置连接超时时间
     try {
         $ossClient->uploadFile(C('ALIYUN_bucket'), $dir . $midStr . $filename, $filepath);
     } catch (OssException $e) {
         return false;
     }
     $ret = str_replace('http://', 'http://' . C('ALIYUN_bucket') . '.', $endpoint . '/' . $dir . $midStr . $filename);
     //返回拼接的http url
     return $ret;
 }
All Usage Examples Of OSS\OssClient::setConnectTimeout