5 Replies - 494 Views - Last Post: 10 December 2012 - 08:51 PM Rate Topic: -----

#1 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Enabling output_buffering in php.ini

Posted 05 December 2012 - 08:08 PM

I ran across an issue on a project where I'm using the header() function to redirect based on app logic. Up until now, it had worked flawlessly. Suddenly, it decided to stop redirecting, (after authentication). So, I looked at my logs and found the "Cannot modify header information..." error. So, I poked around for a while looking for white space. I found two instances, removed them and retried - still didn't work. So, I went poking around for another solution.

I ran across a video on Youtube that suggests turning output_buffering to "On" in php.ini. It had previously been set to 4096. Magically, this fixed my issue.

My question is - is it ok to just enable it or is there some downside?

Is This A Good Question/Topic? 0
  • +

Replies To: Enabling output_buffering in php.ini

#2 Hqtitan  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 51
  • Joined: 28-August 10

Re: Enabling output_buffering in php.ini

Posted 05 December 2012 - 09:55 PM

If you have full access to the webserver, it works fine. But you don't always have full access to the webserver, in fact, you rarely have access to PHP configurations due to security issues. It might be better to echo out a Javascript redirect.

This post has been edited by Hqtitan: 05 December 2012 - 09:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Re: Enabling output_buffering in php.ini

Posted 05 December 2012 - 10:48 PM

Yeah, but Javascript redirects don't work if the client has Javascript disabled.
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Enabling output_buffering in php.ini

Posted 05 December 2012 - 11:39 PM

If you are having to echo Javascript redirects, you are definitely doing something wrong.

Ideally your code should be set up in such a way that any business logic that would require a redirect is done long before any sort of output is rendered. This is where design patterns, like the hugely popular MVC pattern, come in handy.

With that said, if your application was not organized in such a way, enabling output buffering shouldn't cost you much. Not unless your HTML output is unnaturally large, at least. If for some reason your host does not allow you to define your own PHP config files (most decent hosts allow per-directory PHP ini files, or at least a way to define PHP directives through Apache .htaccess files), you can work around that by calling the ob_start() function at the start of pages that need to be buffered. It's essentially the same thing.
Was This Post Helpful? 2
  • +
  • -

#5 Galaxy_Stranger  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 100
  • Joined: 07-February 06

Re: Enabling output_buffering in php.ini

Posted 10 December 2012 - 07:49 PM

Yeah - using ob_start() is like pinpointing the buffering?

I'd like to know if whitespace was the actual cause or not. Is whitespace the only culprit?
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Enabling output_buffering in php.ini

Posted 10 December 2012 - 08:51 PM

I don't know what you mean by "pinpointing the buffering", but using ob_start() just triggers PHP's output buffering, causing anything printed to be buffered until manually flushed, or until the end of the script execution. The config directive you mentioned does the exact same thing, only it does it automatically before any code is executed.

There is no way for us to know if it was caused by a whitespace or not. It's always a likely cause, but any sort of output will cause the same problem. It doesn't really matter what kind of output it is; anything that adds any content to the response body will lock the headers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1