saco721;11041609 wrote:
How would I show a progress bar while the PHP script is running?
Show a progress bar where? If it's in a browser, you'd either have to handle the progress bar in the browser, or you'd have to disable the web servers output buffer (if possible). I'd recommend doing it all in the browser.
You'd also need a way to calculate the total "size" of the progress bar. Doing it apple "migration guide" style is a bad idea. Because if the estimate is so bad that the progress bar will show "less than one minute remaining" for an hour or two, there's a good chance I will turn off my computer.
If you are inserting 100k rows of static data / pre-computed data, you may probably assume that every 10k rows takes ~10% of the total time. But if it takes just a little bit longer to compute the data for each next row, then the last 20k rows might take as much time as the first 80k rows.
Other than that, all you have to do is check progress and compare it to expected total to get the completion ratio , and then fill a progress bar accordingly.
A good first step would be to create a progress bar which fills up by 10% each second for 10 seconds. Then you extend it to take an integer input signifying the total time it should take to fill the progress bar and update it every second. Then you extend it to update at non-second intervals. Finally you use this together with your actual work load.