Google Spreadsheet API: Memory Exceeded

I don't know if anyone has any experience with the Google APIs or the Zend_GData classes, but it's worth it:

When I try to insert a value into a table of 750 rows, it takes a lot of time and then throws an error that exceeded my memory limit (which is 128 MB!). I also got this when querying all the records in this table, but I can do this because it is pretty much data. But why does this happen when inserting a row? It's not too complicated, is it? Here is the code I used:

public function insertIntoSpreadsheet($username, $password, $spreadSheetId, $data = array()) {
    $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
    $client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service);
    $client->setConfig(array( 'timeout' => 240 ));
    $service = new Zend_Gdata_Spreadsheets($client);
    if (count($data) == 0) {
        die("No valid data");
    }
    try {
        $newEntry = $service->insertRow($data, $spreadSheetId);
        return true;
    } catch (Exception $e) {
        return false;
    }
}
+3
source share
3 answers

. insertRow() script 130 000 , 600 . 1.11.

, Zend HTTP POST Atom, , . Google .

, . $values , , . , $spreadsheetKey $worksheetId ( , , , , ).

$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $authService);

function insertRow($httpClient, $spreadsheetKey, $worksheetId, $values) {
    $entry = createEntry($values);
    $httpClient->setUri("https://spreadsheets.google.com/feeds/list/".$spreadsheetKey."/".$worksheetId."/private/full");
    $response = $httpClient->setRawData($entry, 'application/atom+xml')->request('POST');
    return $response->getStatus() == 201;
}

function createEntry($values) { 
    $entry = "<entry xmlns=\"http://www.w3.org/2005/Atom\"";
    $entry .= " xmlns:gsx=\"http://schemas.google.com/spreadsheets/2006/extended\">";
    foreach($values as $key => $value) {
        $entry .= "<gsx:".$key.">".$value."</gsx:".$key.">";
    }
    $entry .= "</entry>";
    return $entry;
}

, .

+4

, , .

insertRow(), .

$token = $httpClient->getClientLoginToken();
$httpClient->setHeaders('Authorization','GoogleLogin auth='.$token);
$httpClient->setHeaders('Content-Type', 'application/atom+xml');
+1

This is a serious Zend_Gdata error. It loads the entire spreadsheet (making an empty request) and loads it into memory only to create the URL of the request to insert. I reported an error as well as a fix, but the problem was ignored by Zend developers and can never be fixed.

0
source

Source: https://habr.com/ru/post/1749174/


All Articles