0

I have a html form:

<form action="/startCode" method="post">
    <input name="id" />
    <input type="submit" />
</form>

It call function in Controller (Laravel framework):

function startCode(Request $request) {
    $ID = $request->id;
    $leng = 2000;
    for ($i = 0; $i < $leng; $i++) {
        // this code insert new record to DB, or edit record which was existed, 
        // it take some seconds, then with $leng = 2000 or more, it take very long times. 
        }
    }

In html, is there a way to make they see the progress of the server side to make sure they are still working?

By the way, there is any way to insert new large number record? instead of each loop.

rome 웃
  • 1,821
  • 3
  • 15
  • 33

1 Answers1

0

You can't add a progress bar in the HTML while the server-side code is running.

The only way to achieve this, is to send the data row by row, or in small batches via chained Ajax requests, tracking the progress with Javascript and visualizing the progress on each Ajax request return.

And on the last sentence: Laravel models have batch insert methods:

http://stackoverflow.com/questions/12702812/bulk-insertion-in-laravel-using-eloquent-orm

beerwin
  • 9,813
  • 6
  • 42
  • 57