Simulate progress bar

0

I have a function in PHP that calculates the amount that each member must pay and then sends him an email. In the Database there are about 4000 users and I would like to know how much is left to the process.

So I want to make a progress bar in HTML that will be updated as I send emails.

The idea I had was that, when starting the process of sending emails, I created a session variable with the total number of emails I had to send and the number of emails that were sent. And, next, in jJavaScript create a setInterval that every 1 second I send an asynchronous AJAX that retrieves the data of the session variable.

But when trying this idea it returns all the requests to me after finishing the process, I mean: if the process takes 5 seconds, it will return to me when the process finishes 5 answers with the value of 100%. I also scan the XHR variable of AJAX, but I only found it for uploading or downloading files.

I would like to know if someone has ideas or has managed to simulate a progress bar.

    
asked by Kazukih 02.06.2017 в 15:32
source

2 answers

0

Another idea if you do not want to use what Xerif says, is to create a temporary file and update it with the shipments that you are doing, and obviously read it every 2 seconds from another window with jquery to show the progress.

    
answered by 03.06.2017 / 10:19
source
0

You must launch the Script in the background so that apache and php create another thread of execution and thus it does not affect your main thread. You can help with the system () function.

$orden = system( "php script_a_ejecutar.php");

Documentation:

link

If at any time the command to be executed with system is going to receive data from the user or from an external source, you should exercise extreme caution and validate the data conscientiously in addition to escape them with the functions provided by php for it, since otherwise It could be a big threat to the server environment.

    
answered by 02.06.2017 в 16:45