Maybe the topic is a little general, the demand is like this.
There is a mass mailing feature. Sometimes the group is sent to hundreds of customers, so it has to be cycled hundreds of times. At the same time there is a page to see in real time the progress of the transmission, dynamic display sent to the first few. The process ID is different each time the message is sent.
The current processing logic for the display page is how much the total number of this process ID in the message table is queried via Ajax and then returned in the page display. This feeling is too inefficient. Once again, check. Excuse me, is there any other good way?
I tried to write the current number of cycles into the session in a loop, and then showed the page read the session value directly, but each time it showed the final result.
I don't know much about PHP threads. Please advise.
Reply to discussion (solution)
Useful Memchache or other cache, write cache in loop script; Show page ajax request background Read cache
Not with Memchche or other caches, I'm going to try HTML5 's localstorage don't know can not.
In the ordinary way, there is no good way. Also do not recommend the landlord to make complex. Proposed landlord still use ajax+ database to get progress, although not so high real-time, but enough to meet the engineering needs. Sending mail can be multi-threaded, which is much more efficient.
Or do not use multithreading, the use of more simple bar. You can http://localhost/xxx.php launch multiple PHP files for sending.