Develop loading in steps with JS / PHP

1

I have a screen in PHP where I have a few steps to do, as these steps are done, the browser stays in white and loading , then I would like to place a loading, where would show for the what is being done.

The steps I do are:

1 - Consultar API.
2 - Calculando Resultados.
3 - Gerando Arquivo.

And each step, is a function I do in PHP. How can I fit a running loading for the user to verify that the process is running?

I use Framework Codeigniter for PHP and Bootstrap.

    
asked by anonymous 25.10.2017 / 21:24

1 answer

-2

A practice to view the status of the code that is being processed on slower or more processed reloads, such as batch processing, file upload, mass mailing, etc., is you using the php flush function, I suggest take a look at the documentation, but summarizing what the flush does is display on the screen what has already been processed to the point where it is and continues processing. link

As you did not put the code, I will put the process in a generic way and you can adapt it to your reality ...

   for($x=0; $x <= 10000; $x++){
        echo 'bloco 1 - linha'. $x.'<br>';

  }

  flush();
//  Aqui ele explode na tela o primeiro bloco antes de começar a processar o segundo...

   for($y=0; $y <= 10000; $y++){
        echo 'bloco 2 - linha'. $y.'<br>';

  }

  flush();
//  Aqui ele explode na tela o segundo bloco antes de começar a processar o terceiro...
for($z=0; $z<= 10000; $z++){
        echo 'bloco 2 - linha'. $z.'<br>';

  }
  //ao completar o processamento ele vai exibir o restante da página
    
26.10.2017 / 03:33