setApplicationName("Client_Library_Examples"); // Warn if the API key isn't set. if (!$apiKey = getApiKey()) { echo missingApiKeyWarning(); return; } $client->setDeveloperKey($apiKey); $service = new Google_Service_Books($client); /************************************************ To actually make the batch call we need to enable batching on the client - this will apply globally until we set it to false. This causes call to the service methods to return the query rather than immediately executing. ************************************************/ $client->setUseBatch(true); /************************************************ We then create a batch, and add each query we want to execute with keys of our choice - these keys will be reflected in the returned array. ************************************************/ $batch = new Google_Http_Batch($client); $optParams = array('filter' => 'free-ebooks'); $req1 = $service->volumes->listVolumes('Henry David Thoreau', $optParams); $batch->add($req1, "thoreau"); $req2 = $service->volumes->listVolumes('George Bernard Shaw', $optParams); $batch->add($req2, "shaw"); /************************************************ Executing the batch will send all requests off at once. ************************************************/ $results = $batch->execute(); ?>