2012-10-02 2 views
0

Google에서 응답을받지 못했습니다. 나는 요청이 99 %의 성공을 거두었지만 최근에 요청이 성공하지 못한다는 것을 알기 시작했다. 실패를 나타내는 응답이 없으므로 실패하지 않습니다. HTTP 상태 코드가없고 XML 응답이 없습니다 ... nada.Google Cloud Storage에서 PUT 요청이 실패 할 수있는 원인은 무엇입니까?

타임 아웃을 너무 낮게 설정하면 원인이 될 수 있습니까? 광산은 여기에 내 코드가 보이는 방법은 10 초

로 설정됩니다

public function putObject($objectPath, $bucket, $accessToken, $metaHeaders) 
{ 
    $version_header = "x-goog-api-version: 2"; 
    $project_header = "x-goog-project-id: ".$this->projectID; 
    $timestamp  = date("r"); 

    $url = 'https://'.$bucket.'.commondatastorage.googleapis.com/object'; 

    $fp = fopen($objectPath, 'r'); 

    $headers = array('Host: '.$bucket.'.commondatastorage.googleapis.com', 
        'Date: '.$timestamp, $version_header, 'Content-Type: text/plain', 
        $project_header, 'Content-Length: '.filesize($objectPath), 
        'Authorization: OAuth '.$accessToken); 
    if(isset($metaHeaders)) 
    { 
     foreach($metaHeaders as $metaHeader) 
     { 
      array_push($headers,$metaHeader); 
     } 
    } 

    $c = curl_init(); 
    curl_setopt($c, CURLOPT_URL, $url); 
    curl_setopt($c, CURLOPT_PUT, 1); 
    curl_setopt($c, CURLOPT_INFILE, $fp); 
    curl_setopt($c, CURLOPT_INFILESIZE, filesize($objectPath)); 
    curl_setopt($c, CURLOPT_HEADER, 1); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT"); 
    curl_setopt($c, CURLOPT_TIMEOUT, 10); //timeout in 10s 
    curl_setopt($c, CURLOPT_HTTPHEADER, $headers); 
    $response = curl_exec($c); 
    curl_close($c); 
    fclose($fp); 

    // split up the response into header and xml body 
    list($header, $xml) = explode("\r\n\r\n", $response, 2); 
    // tokenize 
    $status = strtok($header, "\r\n"); 

    if(stristr($status,"200 OK")) 
    { 
     //success 
     $result = "success"; 
     //check xml object for specific bucket creation errors 

    } 
    else 
    { 
     //failed 
     $result = "fail"; 
     //check xml object for specific bucket creation errors 

    } 

    return $result; 
} 

답변

1

10 초 요청의 크기에 따라 충분하지 않을 수 있습니다. 요청 시간이 오래 걸리면 60 초에 타임 아웃이 시작됩니다. 그리고 이것은 인터넷입니다. 일부 요청은 시간이 초과되어 재 시도해야하지만, 0.001 %보다 훨씬 적어야합니다.

+0

답장을 보내 주셔서 감사합니다. 요청의 크기는 거의 300 바이트가 아니므로 제한 시간을 10 초로 설정 한 것입니다. 하지만 귀하의 조언을 듣고 지수 적 백 오프를 구현하고 실패하면 다시 시도해 보겠습니다. –

관련 문제