PHP Execution longer task, how to output real-time results on the web side

Source: Internet
Author: User
How does PHP perform mass mailings, messages, and so on, and how do I output real-time results on the web?

Reply content:

How does PHP perform mass mailings, messages, and so on, and how do I output real-time results on the web?

Two ideas, one is to separate multiple tasks into a single task, and then the front end each send a request, but this is not very reliable, if the browser crashes or the network is broken down. It is more suitable for situations where task integrity requirements are not high and need to be implemented quickly.

Another idea is that the backend makes a script to receive the task queue asynchronously, and then writes the completion of the task to a cache, the browser side through every time to fetch the cache results to know the back-end script operation.

PHP + Redis task Queue or Gearman

You can use flush functions to view live results, or open OB caches, and then use the ob_flush and flush functions to force the program cache to refresh to the browser to view the results. Hope to be useful to you!

One approach is to use a longer execution time and use the OB series functions to output content instantly, one of which is HTML5 Websocket + PHP socket

The simplest is to flush every output once, if it is nginx to set the buffer as small as possible

Make a queue, execute slowly, perform a change of status, open a page to query the latest completed tasks

Web side = Task Queue <= timed script

According to experience, this approach is better

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

What's wrong with that?

You can take a look at the solution that WordPress uses to update the online installation

Send one, the browser refreshes once, continue to execute the next bar. The URL of the record to perform which step, such as the provision of 5 messages to send a step, xxx/send.php?step=1 after the completion of the page refresh, jump to xxx/send.php?step=2, and so on. Just stepped on my answer, basically can be judged as inexperienced rookie, even this scheme has not seen.

  • 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.