Google Slides API batchUpdate memory exhausted

89 Views Asked by At

I am attempting to do 25 or so text replacement updates via the batchUpdate() function for Google Slides in PHP.

I continue to receive the following error:
Allowed memory size of 536870912 bytes exhausted (tried to allocate 260050944 bytes)

Here is a basic rundown of what I'm doing:

// $report is an array of key-values that are going to be replaced
foreach ($report as $key => $value) {
    $requests[] = createPresentationReplacements($key, $value);
}

$batch_request = new Google_Service_Slides_BatchUpdatePresentationRequest([
    'requests' => $requests
]);

// Assume $client is correctly set and $presentation_id is correct as well
$slide_service = new Google_Service_Slides($client);

// Dies here!
$slide_service->presentations->batchUpdate($presentation_id, $batch_request);

function createPresentationReplacements($key, $value)
{
    return new Google_Service_Slides_Request([
        'replaceAllText' => [
            'containsText' => [
                'text' => '{{' . $key . '}}',
                'matchCase' => true,
            ],
            'replaceText' => $value,
            'fields' => ''
        ],
    ]);
}

I can do up to 2 requests in the update, otherwise I get a memory error. I have logged my memory usage before and after creating the Google_Service_Slides_BatchUpdatePresentationRequest object using memory_get_usage(), and it appears I am not using an enormous amount.

As far as I can tell, the batchUpdate request is either too large when sending, or the response is too large when returned.

Any help would be amazing!

0

There are 0 best solutions below