brianharrell
asked on
PHP flush() not working to flush output to browser before script is done
My script is a basic PHP script calling data from a MYSQL database
but it takes about 2 minutes to run the script as it emails out 1000 people on an email list
I want it to display the email address on screen AS it emails each one instead of all at once at the end of 2 minutes lists them all
I have tried adding
ob_implicit_flush();
at the top, no. that does not work.
and
ob_flush();
flush();
after every echo of the email address to the screen.
Still doesn't work.
help please.
but it takes about 2 minutes to run the script as it emails out 1000 people on an email list
I want it to display the email address on screen AS it emails each one instead of all at once at the end of 2 minutes lists them all
I have tried adding
ob_implicit_flush();
at the top, no. that does not work.
and
ob_flush();
flush();
after every echo of the email address to the screen.
Still doesn't work.
help please.
ASKER
my code say echo instead of print but very much the same.
right after
print('Sent email to: ' . $email);
I put the flush() code but ob_flush() and flush() don't seem to output to browser except when the whole script is done (over 1000 emails)
right after
print('Sent email to: ' . $email);
I put the flush() code but ob_flush() and flush() don't seem to output to browser except when the whole script is done (over 1000 emails)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll test that shortly.
Did that work for you?
ASKER
still waiting to test on a large email batch
ASKER
No that did not work.
In my script I have this near the start of the script (not in the email loop part)
ob_implicit_flush();
ob_flush(); // added 12-05-2007
flush(); // added 11-15-2007 BH
My email script loop is below:
$row = mysql_fetch_array($result) ; // get the data!
if ( $row != "" ) {
// GOT vendor info!
echo "Emailing Vendor ID ".$v_id." ... success!<br>";
ob_flush(); // added 12-05-2007
flush(); // added 11-15-2007 BH
// wait for 100 milliseconds (1 second = 1000000)
usleep(100000);
mail($vendor_email_address _here, $subject, $vendor_message , $extra_stuff_here_from_rep ly_address );
}
Above always prints ALL of them to the screen AFTER it completes the loop.
In my script I have this near the start of the script (not in the email loop part)
ob_implicit_flush();
ob_flush(); // added 12-05-2007
flush(); // added 11-15-2007 BH
My email script loop is below:
$row = mysql_fetch_array($result)
if ( $row != "" ) {
// GOT vendor info!
echo "Emailing Vendor ID ".$v_id." ... success!<br>";
ob_flush(); // added 12-05-2007
flush(); // added 11-15-2007 BH
// wait for 100 milliseconds (1 second = 1000000)
usleep(100000);
mail($vendor_email_address
}
Above always prints ALL of them to the screen AFTER it completes the loop.
ASKER
Also, when a large query is running like this, ALL other queries to that database from browsers seem to STALL until this query finishes emailing the list of 1000 vendors. Isn't MYSQL capable of more than one query at a time from the same browser (Firefox, separate tab)?
ASKER
Tested that issue in IE and it doesn't seem to care how many client files are opened at once while the query is running, must be a FIREFOX issue. Didn't mean to mix issues here but there may be a shred of relevance to the current issue. No need to work on the FFox or IE issue in this thread any more. Back to why the output is not getting to the screen during the emailing...
ASKER
It is erratic and sometimes firefox does them one by one to the screen and other times it waits until 300-500 are to print and others only until the browser finishes the script.
Don't know how to fix this one.
I think it is a browser issue.
Don't know how to fix this one.
I think it is a browser issue.
ASKER
Seems to work in IE now.
So you your code is somethings like:
Open in new window