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.