I have also had varying success using output buffering so I would also
sugger using a shell command that returns the output instead of
printing it. Just to save you any further headache. But ob stuff
should work and I too would be a little interested in knowing of any
dos and don'ts within Cake's classes.

I also saw this in the php manual:
The system() call also tries to automatically flush the web server's
output buffer after each line of output if PHP is running as a server
module.




On Feb 15, 6:41 am, brian <[email protected]> wrote:
> 1.2.1.8004
>
> I've just discovered that upgrading has introduced a problem with my
> app related to output buffering. I remember, a little while back after
> a previous upgrade, that I found a another problem, in my email
> component, because of the way buffering is handled in the controller.
> I'm posting here in case somebody knows what's going on with Cake and
> buffering and can point me in the right direction.
>
> This latest problem is the method below. I'm basically trying to avoid
> the Fileinfo functions.
>
> protected function _getMimeType($filepath)
> {
>         /* because mime_content_type is deprecated but the Fileinfo functions
>          * aren't quite there yet
>          */
>         if (function_exists('mime_content_type'))
>         {
>                 return mime_content_type($filepath);
>         }
>         else
>         {
>                 ob_start();
>                 system('/usr/bin/file -i -b ' . realpath($filepath));
>                 //$type = ob_get_clean();
>                 $type = ob_get_flush();
>                 $parts = explode(';', $type);
>                 return trim($parts[0]);
>         }
>
> }
>
> For some reason, when I'm overwriting a file--and ONLY when
> overwriting--this method causes PHP to barf the "can't modify headers"
> error. So, while I've got your attention, if you can imagine a reason
> why this would only occur on overwrite, I'm all ears.
>
> Anyway, as you can see, I've tried both ob_get_clean() and
> ob_get_flush() with the same bad results. The manual is pretty
> circumspect about which should be used in which situation. I'd
> appreciate any pointers.
>
> More specific to Cake, though, I'd like to know how best to handle
> buffering. This is twice that an upgrade has broken something and so
> I'd like to understand what the best practice is, if any.
>
> BTW, the earlier problem, in the email component, was that rendering
> both a plaintext and HTML view would result in the HTML view having
> the plaintext content also. It turns out that $controller->output is
> concatenated, so it had to be set to null after each render():
>
> $msg = $this->controller->render(null, $layout, $view_path);
> $this->controller->output = null;
>
> This was fun to debug because it looked for all the world like the msg
> parts were borked and I was looking at both the plaintext and HTML
> parts when, in fact, it was just that the HTML part included a lot of
> plaintext. I had to look real close before I realised what had
> happened.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to