Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit 7e729c1

Browse files
committed
Allow increased memory limits to be set via config
1 parent 843d5d6 commit 7e729c1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

config/excel-to-google-sheet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
* instead of a file path.
1515
*/
1616
'service_account_credentials_json' => storage_path('secrets/google-service-account.json'),
17+
18+
/**
19+
* When set, the given memory limit will be used for the duration of the export.
20+
*/
21+
'memory_limit' => null,
1722
];

src/Commands/PushAllExportsToGoogleSheets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Enflow\LaravelExcelToGoogleSheet\GoogleSheetPusher;
66
use Illuminate\Console\Command;
7+
use Illuminate\Database\Eloquent\Model;
78
use Throwable;
89

910
class PushAllExportsToGoogleSheets extends Command

src/Commands/PushExportToGoogleSheets.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function handle(GoogleSheetPusher $googleSheetPusher): int
3232

3333
$this->warn("Pushing {$export} to Google Sheets...");
3434

35+
$this->increaseMemoryLimitIfRequired();
36+
3537
/** @var \Enflow\LaravelExcelToGoogleSheet\ExportableToGoogleSheet $exporter */
3638
$exporter = new $export();
3739

@@ -58,4 +60,17 @@ private function askExport(): ?string
5860

5961
return $exports[$exportName] ?? null;
6062
}
63+
64+
private function increaseMemoryLimitIfRequired(): void
65+
{
66+
$memoryLimit = config('excel-to-google-sheet.memory_limit');
67+
if ($memoryLimit === null) {
68+
return;
69+
}
70+
71+
// `phpoffice/phpspreadsheet` uses a lot of memory while processing the export.
72+
// We'll allow the memory limit to be configured in the config.
73+
// TODO: search for a more long term solution.
74+
ini_set('memory_limit', $memoryLimit);
75+
}
6176
}

0 commit comments

Comments
 (0)