For example, if I have to loop through the background for one hundred times, I need a progress bar on the front end to display the progress of the loop in real time. How can I achieve this with php? Thank you! It may not be explained in detail. The real-time progress is displayed, and the script is being executed. For example, the loop described above is 100 times... for example, if I have to loop through the background for one hundred times, I need a progress bar on the front end to display the progress of the loop in real time. How can I achieve this with php? Thank you!
It may not be explained in detail. The real-time progress is displayed, but the current script is being executed. For example, if the previous cycle is 100 times, the current number of cycles will be returned to the foreground for each loop, can I use js to change the progress bar length to achieve the progress?
Reply content:
For example, if I have to loop through the background for one hundred times, I need a progress bar on the front end to display the progress of the loop in real time. How can I achieve this with php? Thank you!
It may not be explained in detail. The real-time progress is displayed, but the current script is being executed. For example, if the previous cycle is 100 times, the current number of cycles will be returned to the foreground for each loop, can I use js to change the progress bar length to achieve the progress?
I don't know about ajax...
Write a PHP file and output the current progress percentage during access. The front-end javascript sends ajax to access this PHP and parses the number to modify the width of an element on the front-end.
If you don't understand this, you can't just get the last spam code for your reference.
loop.phpfor($i=0;$i<1000;$i++){do_something();file_put_contents("progress.log",$i);}
ajax.phpecho file_get_contents("progress.log")
I don't need javascript, do I?
I know three methods.
I. Regular background training, but frequent ajax requests are generated.
2. Use comet to push content to the frontend. I have done this before. Use a hidden iframe to simulate persistent connections. Then regularly flush the script to the foreground to change the progress bar.
You can refer to some online articles:
Http://en.wikipedia.org/wiki/Comet_ (programming)
Http://www.iteye.com/topic/841554
3. Try nodejs + socket. io and use socket. io to regularly push the background to the foreground.