Skip to content

Commit

Permalink
New config setting and command options memory_limit to set the PHP …
Browse files Browse the repository at this point in the history
…ini value
  • Loading branch information
gonzalom committed Nov 3, 2022
1 parent 2a5ddaa commit 01094a0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ We do not give estimated times for completion on `Accepted` Proposals.

---

## [v9.0.3] - 2022-11-03

`Added`

- New config setting and command options `memory_limit` to set the PHP ini value.

## [v9.0.2] - 2022-04-04

`Fixed`
Expand Down
15 changes: 14 additions & 1 deletion config/model-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

return [

/*
|--------------------------------------------------------------------------
| General settings
|--------------------------------------------------------------------------
|
| - memory_limit: PHP memory limit (https://www.php.net/manual/en/ini.core.php#ini.memory-limit),
| which can be set as `null` to get the default ini value, `-1` to make it unlimited (may end up in OOM errors),
| or a custom value such as 4G or 512M. To check the value that would be used if we leave it as `null`, you
| can run `php -i | grep memory_limit`. Notice: it can also be set as a command option.
|
*/
'memory_limit' => null, // null, -1, 4G, 512M

/*
|--------------------------------------------------------------------------
| Connections
Expand Down Expand Up @@ -53,7 +66,7 @@
| `bulk.connections` (for more information read the config attribute description).
|
*/
'connections' => [],
'connections' => [],

/*
|--------------------------------------------------------------------------
Expand Down
15 changes: 13 additions & 2 deletions src/Console/MakeBulkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ protected function configure()
'c',
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'The connection we want to run.',
config('model-base.bulk.connections', null)
config('model-base.bulk.connections', null),
)
->addOption(
'memory_limit',
'm',
InputOption::VALUE_REQUIRED,
'PHP ini memory_limit, sets the maximum amount of memory that a script is allowed to allocate',
config('model-base.bulk.memory_limit', null),
);
}

Expand All @@ -69,7 +76,11 @@ public function handle()
// Prerequisites for the command to work.
$this->prerequisites();

ini_set('memory_limit', '512M');
$memory_limit = $this->option('memory_limit');
if (null !== $memory_limit) {
ini_set('memory_limit', $memory_limit);
}
$this->output->writeln(sprintf('memory_limit: %s', ini_get('memory_limit')));

// Connections
$connections = $this->getConnectionNames();
Expand Down
15 changes: 14 additions & 1 deletion src/Console/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public function handle()
{
$this->prerequisites();

$memory_limit = $this->option('memory_limit');
if (null !== $memory_limit) {
ini_set('memory_limit', $memory_limit);
}
$this->output->writeln(sprintf('memory_limit: %s', ini_get('memory_limit')));

$tableName = $this->argument('table');
$connection = app('db')->connection($this->option('connection'));

Expand All @@ -63,7 +69,14 @@ protected function getOptions(): array
// ['force', "f", InputOption::VALUE_NONE, 'Force override'],
// ['keep', "k", InputOption::VALUE_NONE, 'Keep existent. No override'],
['connection', 'c', InputOption::VALUE_OPTIONAL, 'The connection we want to use'],
]
[
'memory_limit',
'm',
InputOption::VALUE_REQUIRED,
'PHP ini memory_limit, sets the maximum amount of memory that a script is allowed to allocate',
config('model-base.bulk.memory_limit', null),
],
],
);
}

Expand Down

0 comments on commit 01094a0

Please sign in to comment.