0

I have the following nested foreach loop. While this is executing (it's a biggie) I want follow progress by printing out the output of each iteration as it executes, rather than waiting for it to complete. Just a raw echo would be fine, or even better send the output to a view using AJAX. I'm using Laravel 5.3.

Artist 1:

  • Release 1
  • Release 2
  • Release 3
  • ...

Artist 2:

  • Release 1
  • Release 2
  • Release 3
  • ...

...

$artists = Artist::all();

foreach($artists as $artist) {

    ...get_data...

     $releases = $data->releasees;

    foreach ($releases as $release) {

        $artist_release = new ArtistRelease;

        artist_release->title = $release->title;

        $artist_release->save();

    }
}

Cheers!

loquela
  • 37
  • 7

1 Answers1

1

Content from PHP is typically not displayed until the script has finished running, therefore it's not as simple as running an echo.

You'll need to look at your setup of this operation and make this run as a background task, which you could then query separately. You can check out this SO question for ideas on how to achieve that.

Community
  • 1
  • 1
MacroMan
  • 2,335
  • 1
  • 27
  • 36