How can I display the progress of ajax + php implementation?

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.