Support the ongoing development of Laravel.io →
posted 11 years ago
Queues

Essentially I have an artisan command that processes a file into a database. While there's usually only a few files to process, sometimes there can be hundreds. While processing a few hundred is fine, around the 400-mark I start running into out-of-memory errors (as expected, PHP isn't designed for long-running processes).

To get around this I structured my command as below. I was half-expecting Command::call() to run the command in another process, but that isn't the case.

public function fire() {
    if ($this->option('all')) {
        foreach ($this->getFiles() as $file) {
            $this->call('command:name', ['--path' => $file]);
        }
    } elseif ($this->option('path')) {
        $this->process($this->option('path'));
    }
}

Does anyone know of a way to call an Artisan command in another process? Ideally I'd like to avoid something like shell_exec("artisan command:name --path=$path"); as it seems a bit hacky and depends on being in the project root - but that might be the way? I suppose I could use a queue but it seems a bit over-the-top.

Last updated 2 years ago.
0

The way we handle a similar flow (importing anywhere from 1 day to a few years of data), we have one master command that simply queues the smaller processes so they can be processed one by one. The actual flow is:

  1. Either run a cron every night that runs php artisan import, or manually run the command
  2. The ImportCommand will loop through all accounts and either the previous day or a date range if specified
  3. For each day that needs to be imported, we queue a separate job on a queue
  4. Our queue listener will pull from that queue and process days individually

That way if one job fails, you don't lose the jobs behind it. You can also add more concurrency by adding more workers.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

rmasters rmasters Joined 9 Dec 2013

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.