7
I’m using a loop to send emails from an array.
Every time the loop runs the function sleep(4);
is executed.
The problem is that php output only happens at the end, ie the lines echo "</br>n:".$ne." ".$user["email"]."</br> >>enviado</br>";
are shown in output all at once and after all loops run.
I would like as each loop runs, the echo function is displayed (one by one and not at once at the end).
foreach($users as $user) {
$message->setTo($user["email"], $user["nome"]);
echo "\n";sleep(4);
flush();
ob_end_flush();
echo date('h:i:s');
$mailer->send($message);
echo date('h:i:s') . "\n";
$ne++;
echo "</br>n:".$ne." ".$user["email"]."</br> >>enviado</br>";
Very poorly crafted question, explain and detail better.
– Edson Horacio Junior
I think it’s clear now ...I edited the question...
– I-am Sam
This script runs in a browser or terminal?
– Edson Horacio Junior
in php browser
– I-am Sam
The PHP code is interpreted by the server, when the process ends the answer is returned to the browser, so it appears all at once. If this pause is necessary you will have to do this process via javascript/jQuery using AJAX requests.
– Edson Horacio Junior
Okay thanks I’ll investigate how to do that
– I-am Sam
@Edsonhoraciojunior wrong. If you want the result out in ranks you can too. I will answer the question.
– Wallace Maxters
I didn’t know the method quoted by @Wallacemaxters, good!
– Edson Horacio Junior
@Edsonhoraciojunior I also thought it was not possible to do this in PHP, but after I saw a javascript/php implementation with Stream updates and ob_implict_flush I changed my mind. http://www.html5rocks.com/en/tutorials/eventsource/basics/
– Wallace Maxters
And I don’t know if I’m wrong, but I think because of the ignorance of some that boy took negative votes.
– Wallace Maxters
The downvote people sneak out, as always :p
– Wallace Maxters