I have recently started using ob_flush(); flush(); to try and update the browser when there is a function that takes a while to process. It seems like this has been causing functionality problems in other areas of the script though.

Does flush/ob_flush clear php files or do anything that would cause the script to function differently besides flushing the output?

I'm not sure if I'm confused. From the sounds of it the buffer is just the html/outputed data that is going to the browser.

Could someone also confirm that I'm using the flush functions for the right reason, which is to update the clients browser so it doesn't timeout?

Thanks in advance,

Justin

    I wouldn't say so it doesn't time-out, although that could be one thing it does.

    The reason for output buffering (that I've seen) is to hide content from the browser so that if in the event that something goes wrong, and you need to direct them somwhere else via header() or start a new session or something that requires no headers being sent, it holds headers being sent back, thus giving you control over your entire script.

    It can also be used to flush the contents of a function that is running 1 million times and taking a while so that the user gets some form of feed-back.

    It should only affect your site by delaying or hastening the output to the browser. Performance issues shouldn't show up unless you're really doing something wrong (which is hard to do without PHP telling you).

    Did I help you, or confuse you?

      That is what I thought it did. Even though you've clarified/confirmed what it does I'm confused as to why having the ob_flush(); flush(); code run would cause some things not to function. It just doesn't make sense.

      I can't paste the code, but I can give you a gyst of what it does.

      session_start();
      -require files-
      -mysql queries-
      -cpanel/whm function call-
      -mail is sent using a custom mail class I created-

      Now the script started having trouble with a mysql update query and the mail sending. The only thing added was:

      ob_flush();
      flush();

      And it was between the mysql queries and the mail function. The cpanel/whm function would run fine.

      So as you can see it just doesn't make sense and I can't recreate it on my test server. It was happening on another server and the removal of ob_flush(); flush(); removed the problems.

      It happened in another area as well that I was able to recreate.

      I'm thinking I must be doing something wrong.

        Okay, so can you generalize your code? It's hard to get exactly what's going on without code. I don't want to see what's your secret is, just what you're doing with ob_flush and all that. If you can, generalize/remove sensitive info and paste your code. It would help a lot.

          There is a lot of code for what I'm referring to. I think I'm going to put together a small script to try and recreate the problem though.

          I don't know how long that will take though, so I'll post once I have that ready.

          Thanks for your help so far. Just the confirmation itself was very helpful.

            Write a Reply...