Jump to content

Script Output times out


Larry101

Recommended Posts

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?

Link to comment
Share on other sites

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"; 


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.