because the flush happens after everything is done, including the fputs thingy.
you have to call ob_get_contents() or something like that. I always to this ob_start(); do something $data = ob_get_contents(); ob_end_clean(); then I work with the $data later. but if you don't use the ob_get_contents(); or ob_end_clean(); then PHP waits until everything is done, and then flushes. Jim ----- Original Message ----- From: "Alex Lance" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, March 09, 2003 2:22 AM Subject: [PHP] ob_start -- output buffer problem > > Hi all, > > to quote from http://www.php.net/manual/en/function.ob-start.php > > > void ob_start ( [string output_callback]) > > > > An optional output_callback function may be specified. This function > > takes a string as a parameter and should return a string. The function > > will be called when ob_end_flush() is called, or when the output > > buffer is flushed to the browser at the end of the request. > > My callback function does not get called unless I manually call > ob_end_flush(). > > I'm not interested in calling ob_end_flush() at all, I want my callback > function to be called "when the output buffer is flushed to the browser > at the end of the request" so the question is why isn't this happening? > > here's my example: > > <?php > > $x = new test(); > > echo "hey"; > > // IF next line is uncommented so it manually flushes > // then the finish method WILL get called. But I need > // get around calling anything at the *end* of a script. > > //ob_end_flush(); > > > class test { > > var $msg_file = "cooked_html/error_log2"; > > function test() { > ob_start(array(&$this, "finish")); > $this->msg("got to initialize"); > } > > function finish($page) { > $this->msg("GOT TO FINISH!!!"); > return $page; > } > > function msg ($msg) { > $msg = "\n" . exec("date") ." ::: ". $msg; > $fp = fopen($this->msg_file, "a") or die ("cannot open ".$this->msg_file); > fputs ($fp, $msg, strlen($msg)) or die ("cannot write to ".$this->msg_file); > fclose($fp); > } > > } > > ?> > > > But if ob_end_flush() IS called then the error log WILL have the "GOT TO > FINISH" message. > > Any ideas on why the output is not being flushed automatically? > thanks > Alex > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php