hi,

I'd like to know what exactly the funcionality of ob_start is? I know it is for buffering output, but what exactly does that mean? I have an ftp script, and I'm using ob_start and ob_end_flush which I notice makes the page load a little faster. but I'm wondering what the actual purpose of it is.

Brandon

    This just means that PHP will wait until the script is completed before sending the data. So it may look 'cleaner' coming up. Having output buffering off will send data as it's parsed so it looks a bit choppy, but might be a miniscule amount faster this way.

      I see. Even it may be a tad slower with puffering turned on, could it mean a bit of increase in speed when working with ftp commands in php? It only seemed that the case when I did that. And, I read in the php manual that you could have nested output buffers, so what would this mean, or the possible use.

      Brandon

      Originally posted by Wynder
      This just means that PHP will wait until the script is completed before sending the data. So it may look 'cleaner' coming up. Having output buffering off will send data as it's parsed so it looks a bit choppy, but might be a miniscule amount faster this way.

        Nested output buffers -- so, I'm just assuming you could have information display as it was processed, but if you wanted to wait for a block of information to process before showing, you could turn on buffering, let it display, then turn it off again.

        Now, this isn't a typical example, but check this out:

        http://devnull.dtcc.edu/buffer.php

        This is and example of something I did for a friend who was running a web-based CyberPunk game and wanted to do a fun website.

        Note (If it pauses and you just get the black page, just hit refresh. 🙂)

          I see....that's interesting. how did you do that? what did you use to do that. that's kind of neat how each block shows up like that!

          and my other question also that I asked in the last post, is it possible in any way that using this might speed up a page using ftp commands? like I said it seemed to do so for me. not sure how, but it made it so that a page with about 30 to 35 files and directories in all on one page went from loading in about 20 seconds to about 5 or 6 seconds using this. not sure how

          Brandon

            To be clear...

            "Output buffering" in php, as the name suggests, is for buffering alot of data that would otherwise be printed to STDOUT. So, there are many uses as opposed to just buffering pages to display in one chunk. For example, if you have alot of data that gets printed to the screen/browser and the only way for you to manipulate it is storing it to an output buffer:

            ob_start();
            include('myfile.txt');
            $myfile = ob_get_contents();
            ob_end_clean();
            
            $myfile = str_replace(' ', '', $myfile);
            // continue execution...
            

            Anything that gets printed to screen, including errors/warnings and anything echo()'d, print()'d wil get nstored in the buffer for you to play with.

              Here's the code:

              <?php
                 sleep(2);
                 slow_type("Standby...<p>");
                 sleep(1);
                 slow_type("...Netcore Access Chip Detected.<br>");
                 sleep(1);
                 slow_type("...Encrypting Connection.");
                 sleep(2);
                 echo(" <b>Done!</b><br>");
                 slow_type("...Initializing Indentity Confirmation.");
                 sleep(1);
                 echo(" <b>Done!</b><br>");
                 slow_type("...Bringing up the network.<p>");
                 sleep(2);
                echo("<body bgcolor=\"#000000\"><font color=white>");
                 echo("</pre>");
                 echo("<center><b>");
                 vslow_type("Welcome... ");
                 sleep(1);
                 echo(" =)");
              ?>
              
              <?php
              //And the accompanying functions:
              
                 //This function displays a string to appear as if it's being
                 //typed.  Requires output_buffer=off in php.ini.
                 function slow_type( $message )
                 {
                    for($i = 0; $i < strlen($message); $i++ )
                    {
                       echo("$message[$i]");
                       usleep(rand(10000,100000));
                    }
                 }
              
                 //This function displays a string to appear as if it's being
                 //very slowly typed.  Requires output_buffer=off in php.ini.
                 function vslow_type( $message )
                 {
                    for($i = 0; $i < strlen($message); $i++ )
                    {
                       echo("$message[$i]");
                       usleep(350000);
                    }
                 }
              ?>
              

                whoa that's pretty creative there. I've never seen the function usleep, but I just looked at the php manual and it was there.

                the thing with ftp commands in php, is, on my system anyway, and I"ve heard this could be changed, if the script isn't finished within 30 seconds, it stops and throws a fatal error. so, if you use too many ftp commands on one page, it takes longer to execute, and often times when you have 25 / 30 files on a page listed, it will only get through to about 20 of them. so that's why I was trying to find something to maybe speed it up a bit.

                and I just discovered how to find out how long it took the page to load, thanks to microtime.

                I tried looking at net2ftp's code with some of the things it has on there...but with those types of scripts which are downloaded and used often, there are functions everywhere, and in about who knows how many files, and can't find what is where.

                Brandon

                Originally posted by Wynder
                Here's the code:

                <?php
                   sleep(2);
                   slow_type("Standby...<p>");
                   sleep(1);
                   slow_type("...Netcore Access Chip Detected.<br>");
                   sleep(1);
                   slow_type("...Encrypting Connection.");
                   sleep(2);
                   echo(" <b>Done!</b><br>");
                   slow_type("...Initializing Indentity Confirmation.");
                   sleep(1);
                   echo(" <b>Done!</b><br>");
                   slow_type("...Bringing up the network.<p>");
                   sleep(2);
                  echo("<body bgcolor=\"#000000\"><font color=white>");
                   echo("</pre>");
                   echo("<center><b>");
                   vslow_type("Welcome... ");
                   sleep(1);
                   echo(" =)");
                ?>
                
                <?php
                //And the accompanying functions:
                
                   //This function displays a string to appear as if it's being
                   //typed.  Requires output_buffer=off in php.ini.
                   function slow_type( $message )
                   {
                      for($i = 0; $i < strlen($message); $i++ )
                      {
                         echo("$message[$i]");
                         usleep(rand(10000,100000));
                      }
                   }
                
                   //This function displays a string to appear as if it's being
                   //very slowly typed.  Requires output_buffer=off in php.ini.
                   function vslow_type( $message )
                   {
                      for($i = 0; $i < strlen($message); $i++ )
                      {
                         echo("$message[$i]");
                         usleep(350000);
                      }
                   }
                ?>
                

                [/B]

                  Very neat Wynder, would have never thought of doing something like that.

                    You can change the amount of time PHP will wait for a script to execute with set_time_limit()

                      aha, great, thanks! you probably just saved me a few headaches lol. but still I try to make it not too long for the sake of the user using it. who wants to have to wait for 20 - 30 seconds for a page to load, every single time one has to load. but, thanks, if needed I will definitely use it, or may use it anyway, just to be safe. I may also look for that max_execution_time part in php.ini that the phpmanual mentions when talking about set_time_limit. thanks

                      Brandon

                      Originally posted by superwormy
                      You can change the amount of time PHP will wait for a script to execute with set_time_limit()

                        Write a Reply...