title: Make requests and handle responses for resumable upload: Google Drive api [php]
body: <p>I'm using the API Client Library for PHP (Beta) to work with google drive api, So far I can authorize and and upload a file in chuncks.
  According to the <a href="https://developers.google.com/drive/web/manage-uploads#resumable" rel="noreferrer">documentation</a>, these three steps should be taken to upload a file:</p>
  <blockquote>
  <ul>
  <li>Start a resumable session.</li>
  <li>Save the resumable session URI.</li>
  <li>Upload the file.</li>
  </ul>
  </blockquote>
  <p>Which I think the Client Library handles.
  Again, according to the documentation, if I want to show the progress or <a href="https://developers.google.com/drive/web/manage-uploads#resume-upload" rel="noreferrer">resume an interrupted upload</a>, or to handle errors I need to capture the response and also be able to send requests like this:</p>
  <pre><code>&gt; PUT {session_uri} HTTP/1.1 Content-Length: 0 Content-Range: bytes
  &gt; */2000000
  </code></pre>
  <p>But I have no idea how should I make such request and where can I get the response from, the php code I'm using to upload,like any other php code, only returns values when it is done executing, which is when the upload is done.
  here is the function I'm using to upload files (Resumable):</p>
  <pre><code>function uploadFile($service,$client,$filetoUpload,$parentId){
      $file = new Google_Service_Drive_DriveFile();
      $file-&gt;title = $filetoUpload['name'];
      $chunkSizeBytes = 1 * 1024 * 1024;
      
      // Set the parent folder.
        if ($parentId != null) {
          $parent = new Google_Service_Drive_ParentReference();
          $parent-&gt;setId($parentId);
          $file-&gt;setParents(array($parent));
        }
    
      // Call the API with the media upload, defer so it doesn't immediately return.
      $client-&gt;setDefer(true);
      $request = $service-&gt;files-&gt;insert($file);
      
      // Create a media file upload to represent our upload process.
      $media = new Google_Http_MediaFileUpload(
        $client,
        $request,
        $filetoUpload['type'],
        null,
        true,
        $chunkSizeBytes
      );
      $media-&gt;setFileSize(filesize($filetoUpload['tmp_name']));
      
      // Upload the various chunks. $status will be false until the process is
      // complete.
      $status = false;
      $handle = fopen($filetoUpload['tmp_name'], &quot;rb&quot;);
  
      while (!$status &amp;&amp; !feof($handle)) {
        set_time_limit(120);    
        $chunk = fread($handle, $chunkSizeBytes);
        $status = $media-&gt;nextChunk($chunk);
       }
      
      // The final value of $status will be the data from the API for the object
      // that has been uploaded.
      $result = false;
      if($status != false) {
        $result = $status;
        set_time_limit(30);
        echo &quot;&lt;pre&gt;&quot;;
        print_r($result);
      }
      
      fclose($handle);
      // Reset to the client to execute requests immediately in the future.
      $client-&gt;setDefer(false);
  }
  </code></pre>
  <p>Should i make a separate php file to handle these requests?
  if so, How should tell that which file's status I'm requesting for?
  Thanks.</p>