fix: [internal] Try to cleanup memory when fetching feed

pull/9479/head
Jakub Onderka 2024-01-12 15:16:31 +01:00
parent d2911274b5
commit 518b2faa94
2 changed files with 5 additions and 4 deletions

View File

@ -187,7 +187,7 @@ class CurlClient extends HttpSocketExtended
// Share handle between requests to allow keep connection alive between requests
$this->ch = curl_init();
if (!$this->ch) {
throw new \RuntimeException("Could not initialize cURL");
throw new \RuntimeException("Could not initialize curl");
}
} else {
// Reset options, so we can do another request
@ -237,7 +237,7 @@ class CurlClient extends HttpSocketExtended
};
if (!curl_setopt_array($this->ch, $options)) {
throw new \RuntimeException('cURL error: Could not set options');
throw new \RuntimeException('curl error: Could not set options');
}
// Download the given URL, and return output
@ -248,7 +248,7 @@ class CurlClient extends HttpSocketExtended
if (!empty($errorMessage)) {
$errorMessage = ": $errorMessage";
}
throw new SocketException('cURL error ' . curl_strerror(curl_errno($this->ch)) . $errorMessage);
throw new SocketException('curl error ' . curl_strerror(curl_errno($this->ch)) . $errorMessage);
}
$code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

View File

@ -2062,6 +2062,7 @@ class Feed extends AppModel
$contentType = $response->getHeader('content-type');
if ($contentType === 'application/zip') {
$zipFilePath = FileAccessTool::writeToTempFile($response->body);
unset($response->body); // cleanup variable to reduce memory usage
try {
$response->body = $this->unzipFirstFile($zipFilePath);
@ -2198,7 +2199,7 @@ class Feed extends AppModel
ZipArchive::ER_READ => 'read error',
ZipArchive::ER_SEEK => 'seek error',
];
$message = isset($errorCodes[$result]) ? $errorCodes[$result] : 'error ' . $result;
$message = $errorCodes[$result] ?? 'error ' . $result;
throw new Exception("Remote server returns ZIP file, that cannot be open ($message)");
}