How to output real-time results on the web end for php tasks that have been executed for a long time

Source: Internet
Author: User
How can I output real-time results on the web end when executing tasks such as Group emails and messages in php? How can I output real-time results on the web end when executing tasks such as Group emails and messages in php?

Reply content:

How can I output real-time results on the web end when executing tasks such as Group emails and messages in php?

One approach is to split multiple tasks into a single task, and then send a request at the front end each time. However, this is not very reliable. If the browser crashes or the network is disconnected, it will crash. It is suitable for scenarios where task integrity is not high and quick implementation is required.

Another idea is to make a script at the backend to asynchronously receive the task queue, and then write the task completion status to a cache, the browser obtains the cached results at intervals to learn the running status of the backend scripts.

Php + redis task queue or gearman

AvailableflushFunction to view Real-time results, or enable ob cache, and then useob_flushAndflushFunction to forcibly refresh the program cache to the browser to view the results. Hope to be useful to you!

One method is to set a long execution time and use ob functions to output content instantly. The other is Html5 Websocket + php socket.

The simplest is to flush the output result every time. If nginx is used, set the buffer as small as possible.

Make it into a queue, execute it slowly, execute the completed status change, open a page to query the latest executed tasks

Web terminal => task queue <= scheduled script

Based on experience, this method is better

Http://my.oschina.net/u/657911/blog/178677

What's wrong?

You can refer to the solution used by wordpress during the security update process.

Send one, refresh the browser once, and continue to execute the next one. Which step is recorded in the url, for example, to send five emails as one step, xxx/send. php? Step = 1 after the execution is complete, the page is refreshed and jumps to xxx/send. php? Step = 2, and so on. When I step on my answer just now, I can basically identify it as a novice with insufficient experience. I have never seen such a solution.

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.