I am working on a newsletter managing webapp. And when I am launching the process it can take a while to finish (to send emails). So I'am currenlty looking to refresh a css div in my view to show the status but I'am stuck.
I read articles on forum regarding this issue but don't find something clear.
& if you want it to show a percent loading bar, or percent complete, etc, you will need some very fancy code. Can't help you much there. If you want it to simply say "loading" or something, just use JS to set a invisible div (that says "loading") to be visible. ajax is not necessarily needed actually. &you are not giving much details
Not sure what you mean. PHP obviously can't talk directly with JS. You probably need a hidden div in your view that says "loading". You probably also have a link or button to send the emails. Have jquery set the div as visible when the button/link is pressed, and send an ajax request to the email page. Give it a large timeout. When the request is successful, hide the div again and unhide a div that says "Successful" or something.
You could create a polling mechanism that frequently sends AJAX requests to receive the current progress information. And the mailer would have to write somewhere, how many mails where already sent. You could use APC for this. Just some ideas…
It basically uses the same concept: On the clientside you have to write code, that frequently sends a request to ask for the current progress. The response might contain a JSON object with information, how many mails where already sent, how many failed, etc.
To get this response, the mail sender process first needs to save this information somewhere. You could use APC to store this value with a specific key to the cache after each email was sent.
And in the controller that replies to your AJAX requests, you simply look in APC, what value is there and return the JSON object.
Main problem will be, to create a mailer process that forks from a PHP request and runs in background, after the mail sending has been initiated. Try to google for "PHP fork process" or something. There are solutions for it. But might get a little tricky.