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.