LITTLEBLACKDOG.COM Forum Index LITTLEBLACKDOG.COM

 
LWD LWD   FAQ FAQ   Memberlist Memberlist   Usergroups Usergroups   Active Topics Active Topics   Register Register  
  Profile Profile   Log in to check your private messages Log in to check your private messages   Log in Log in  
  Who is Online Who is Online   Image Gallery Image Gallery   Chat Chat   Search Search  
  LWDGear       LBDGear  

View next topic
View previous topic
Post new topic     Reply to topic   LITTLEBLACKDOG.COM Forum Index » Code Warriors
Author Message
fathertyme
Site Admin
Site Admin


Joined: 30 Jun 2001
Posts: 6213
Location: The American Colonies

Post Posted: Tue Feb 18, 2003 1:01 am   Post subject: display output before php code ends... Reply with quote Back to top  

so I've got a rather hefty set of PHP code, that I run on a regular basis. it takes like 5-15 minutes to run, depending on how the net is doing.

The problem is that it doesn't display anything until all the processing is done, and then it hits you with it all at the end.

What I'd like to do is give updates, then clear the screen and show the final product...

as an additional challenge, I'd like to be able to have numbers change, or a scroll bar, or something to indicate status, eg: 10% done, 20 % done...

anyone know how I can do any of this?

_________________
LWD web-cams: http://lwdcam.codecoma.com/?lwdcam
----

---
[9:08pm][09/16/2005]«+ flip » college...what is that
[9:08pm][09/16/2005]«+ Aff » apparently a place where you find rum
---
I used to live in my own little world, but they didn't like me there either.

You see dead people? I'm a software engineer, I don't see anybody!
---
My Amazon Wishlist
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 25
Posts: 12198
Location: The Constitution State

Post Posted: Tue Feb 18, 2003 6:45 am   Post subject: Reply with quote Back to top  

PHP is open source isn't it? Rip it apart and customize it yourself, and then build it as a cgi module or a brand new apache plug-in. But otherwise, that's just the nature of the beast.

_________________
To the top of hunger mountain
I found my solitary ways
Where I could live on nuts and honey
And take my shelter in a cave
View user's profile Send private message
Webster
Guide Dog
Guide Dog


Joined: 16 Feb 2002
Age: 28
Posts: 8701
Location: Vacationland

Post Posted: Tue Feb 18, 2003 6:55 am   Post subject: Re: display output before php code ends... Reply with quote Back to top  

I think that there's a way to clear the buffer as it goes along, correct? I'd have to look it up for the syntax, haven't done PHP for some 6-8 months or so. Depending upon the type of output you are creating, you could have it begin creating the page and display results as it goes along, such as with a long list of items, or you could just output some sort of status and then display it all at the end. You could use a div with an id/name tag and use javascript to hide your results output as you go along to keep the page clean (yeah yeah, it's a hack job, but its easy)

_________________
www .Run To Win.com
The Marathon Thread
I finally published my book: Comprehensive Guide to Marathon Preparation & Recovery
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 25
Posts: 12198
Location: The Constitution State

Post Posted: Tue Feb 18, 2003 9:19 am   Post subject: Reply with quote Back to top  

You're right. A quick peek at the PHP manual and I found this:

The flush function

Code: Select all
void flush( void )


Quote:
Note: flush() has no effect on the buffering scheme of your webserver or the browser on the client side.

Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.

Server modules for Apache like mod_gzip may do buffering of their own that will cause flush() to not result in data being sent immediately to the client.

Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen.

Some versions of Microsoft Internet Explorer will only start to display the page after they have received 256 bytes of output, so you may need to send extra whitespace before flushing to get those browsers to display the page.

_________________
To the top of hunger mountain
I found my solitary ways
Where I could live on nuts and honey
And take my shelter in a cave
View user's profile Send private message
random
Moderator
Moderator


Joined: 30 Oct 2000
Posts: 3382
Location: Left Field

Post Posted: Tue Feb 18, 2003 1:56 pm   Post subject: Reply with quote Back to top  

How well do you know the Ming libraries?

This is just a theory but maybe you can use ming to create a flash graphic that will display the progress. If you get that far it shouldn't be too much more difficult to display some data while in the process.

I just started playing with ming so i ain't sure that will work. Neutral

_________________
Democracy substitutes election by the incompetent many for appointment by the corrupt few. -George Bernard Shaw
Code: Select all
function video() {
die("radio star");
}
View user's profile Send private message Send e-mail AIM Address ICQ Number
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 25
Posts: 12198
Location: The Constitution State

Post Posted: Tue Feb 18, 2003 2:41 pm   Post subject: Reply with quote Back to top  

How about frames? The PHP code in one frame, an HTML page in another that would update in intervals. Actually the second frame can also be a PHP to access server side resources, and the first script would have to output progress into a shared data source.

_________________
To the top of hunger mountain
I found my solitary ways
Where I could live on nuts and honey
And take my shelter in a cave
View user's profile Send private message
Fido
Big Dog
Big Dog


Joined: 18 Oct 2000
Posts: 4410

Post Posted: Tue Feb 18, 2003 4:03 pm   Post subject: Reply with quote Back to top  

I used some code recently that did what you're asking. I think they broke down the processing into sections though, and used META REFRESH functions to update the page as it went along. From what I can tell, here is the section of code that does this. Might help you a bit, at least in theory.

Code: Select all

   //
   // Search tables regeneration
   //
   case 'searchfill':
      $step = (!empty($_GET['step'])) ? $_GET['step'] : '';
      
      if ($step == 'cancel')
      {
         if (empty($convert_settings['board_disable']))
         {
            save_config('board_disable', 0);
         }
         else
         {
            unset($convert_settings['board_disable']);
            save_config('convert_settings', $convert_settings);
         }

         message_die(GENERAL_MESSAGE, $lang['Indexing_stop_explain'] . $return_convert . $return_index);
      }

      if (!isset($_GET['start']))
      {
         if ($step == 'remove_common')
         {
            $percentage = 20;

            $sql = 'SELECT COUNT(*) AS total FROM ' . POSTS_TEXT_TABLE;
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $common_threshold = floor(($row['total'] * $percentage) / 100);

            $sql = 'SELECT MIN(word_id) AS min_id, MAX(word_id) AS max_id FROM ' . SEARCH_WORD_TABLE ;
         }
         else
         {
            $sql = 'SELECT MIN(post_id) AS min_id, MAX(post_id) AS max_id FROM ' . POSTS_TEXT_TABLE;
         }

         $result = $db->sql_query($sql);
         $row = $db->sql_fetchrow($result);

         $start = $row['min_id'];
         $max = $row['max_id'];
      }
      else
      {
         if ($step == 'remove_common')
         {
            $common_threshold = $_GET['threshold'];
         }

         $start = intval($_GET['start']);
         $max = $_GET['max'];
      }

      switch ($step)
      {
      //
      // Step 4: remove common words
      //
      case 'remove_common':
         while (still_on_time() && ($start <= $max))
         {
            $end = $start + 500;
            $sql = 'SELECT word_id, COUNT(*) AS total'
               . ' FROM ' . SEARCH_MATCH_TABLE
               . ' WHERE word_id BETWEEN ' . $start . ' AND ' . $end
               . ' GROUP BY word_id'
               . ' HAVING total > ' . $common_threshold;
            if (!$result = $db->sql_query($sql))
            {
               message_die(GENERAL_ERROR, 'Could not retrieve common words.', '', __LINE__, __FILE__, $sql);
            }

            $word_ids = array();
            while ($row = $db->sql_fetchrow($result))
            {
               $word_ids[] = $row['word_id'];
            }
            if (count($word_ids))
            {
               $sql = 'UPDATE ' . SEARCH_WORD_TABLE
                  . ' SET word_common = 1'
                  . ' WHERE word_id IN (' . implode(', ', $word_ids) . ')';

               if (!$db->sql_query($sql))
               {
                  message_die(GENERAL_ERROR, 'Could not mark common words.', '', __LINE__, __FILE__, $sql);
               }

               $sql = 'DELETE FROM ' . SEARCH_MATCH_TABLE
                  . ' WHERE word_id IN (' . implode(', ', $word_ids) . ')';

               if (!$db->sql_query($sql))
               {
                  message_die(GENERAL_ERROR, 'Could not delete common words.', '', __LINE__, __FILE__, $sql);
               }
            }

            $start = $end + 1;
         }
         if ($end >= $max)
         {
            if (empty($convert_settings['board_disable']))
            {
               save_config('board_disable', 0);
            }
            else
            {
               unset($convert_settings['board_disable']);
               save_config('convert_settings', $convert_settings);
            }

            $convert_settings['searchfill_lock'] = TRUE;
            save_config('convert_settings', $convert_settings);

            message_die(GENERAL_MESSAGE,  $lang['Indexing_finished_explain'] . $return_convert . $return_index);
         }
         $percentage = (($max / $end) == 0) ? 0 : floor(100 / ($max / $end));
         $msg = sprintf($lang['Step_percent_completed'], 3, 3, $percentage);
         $url = 'index.' . $phpEx . '?mode=searchfill&step=remove_common&threshold=' . $common_threshold . '&max=' . $max . '&start=' . $start;

         meta_refresh($url);
         message_die(GENERAL_MESSAGE, $msg . $stop_indexing_link);
      break;

View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic     Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours

Help us keep advertisements off this site. Donate today!