One thing I have noticed with php, is that nothing is output to the screen until the script has stopped working. For the project I am working on I feed in a list of over 100
It may be better to store all script output in a buffer then flush the buffer when required.
For example:
$val) { echo $test; ob_flush(); flush(); } ob_end_flush(); ?>
Make sure you have mod_gzip disabled!