Larry101 Posted July 12, 2011 Share Posted July 12, 2011 Hi - I have a script that does lots of work in loops in loop using a database. I have coded lots of echo's to out put as it goes, problem is.. it doesn't output until the very end of the task - whgick is OK on a short run, but when it processes a really long loop it just doesnt out put anything and gets stuck. I have tried ob_start and ob_flush but it didnt make any difference. Any ideas on how to make a long script process output as it goes? Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/ Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 can you post the code you are using please... Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/#findComment-1241798 Share on other sites More sharing options...
Larry101 Posted July 12, 2011 Author Share Posted July 12, 2011 I have striped the code to this... basically the on a long run the echos dont output and the browser gets stuck. <? $sql = "select * from table where processed_state = \"Pending\" limit 1000 "; $qry = mysql_query($sql, $conn) or die ("FAILED: " .mysql_error()); while($rows = mysql_fetch_assoc($qry)){ // loop through Pending data - OUTTA LOOP ************************************************************* echo " OUTPUT DATA HERE"; for ($i=1; $i<=500; $i++){ // INNER LOOP ------------------------ //more code echo " OUTPUT DATA HERE"; //more code //more code //more code echo " OUTPUT DATA HERE"; } // for - INNER LOOP ------------------------------------ //more code //more code echo " OUTPUT DATA HERE"; //more code }// while - OUTTA LOOP *********************************************************************************************************************** echo " OUTPUT DATA HERE"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/#findComment-1241818 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 I would need to see the entire for loop code in order to suggest methods of optimizing your code. As I see it now, you are looping a loop 500 times for each iteration of the while loop.....terrible idea, no wonder your memory expires Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/#findComment-1241820 Share on other sites More sharing options...
Larry101 Posted July 12, 2011 Author Share Posted July 12, 2011 Unfortunately the actual loop script is commercially sensitive and very long so I cant publish it BUT do you think if I removed the 'for' loop it would solve my problem? In reality the loop runs 10k plus times in the script. Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/#findComment-1241834 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 if it is not necessary, most certainly remove it. Also, you can look into using mysql_free_result to free all memory associated with your mysql identifier, if you are using multiple queries Quote Link to comment https://forums.phpfreaks.com/topic/241797-script-output-times-out/#findComment-1241839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.