PHP output buffereing

kchapple wrote on Monday, April 11, 2011:

I ran into a problem while developing the CDR module.  The module heavily uses header(“Location…”) to redirect the browser around the UI.  I was getting a lot of white screens because of it.  Looking at the php error log, I figured out that the problem was rooted in the way we use php tags… Throughout openemr, there are an abundance of spaces, which get outputted to the browser before the “headers” are actually sent, which causes errors, and prevents the redirection.  Aron also created a bunch of these when he added his copyright notice.  Also, a general rule of thumb is to leave off the last end php tag in a php file, which helps avoid this problem.  To fix this, I enabled output buffering, which is a workaround for this problem “with the overhead of all of your output to the browser being buffered in the server until you send it.” Anyways, that being said, we should add this setting to the required php.ini settings upon release of the CDR module (at least until we have time to track down and remove the spaces):

output_buffering = On

Thoughts?

Ken
http://www.mi-squared.com

penguin8r wrote on Monday, April 11, 2011:

I have had Output Buffering enabled on several servers due to it’s being required for the mobile portal to work, haven’t seen any negative consequences from it yet.  I suppose it might be worth looking into reworking the code in the mobile portal so it’s not required.

sunsetsystems wrote on Monday, April 11, 2011:

Ken I’d like to see some sample code that demonstrates your navigation methods and the problem you’re having.  It may not be so hard to clean up the code as needed without requiring a kludge.

By the way make sure restoreSession() is being called on the client side prior to web server requests.

Rod
www.sunsetsystems.com

kchapple wrote on Monday, April 11, 2011:

The CDR branch is still in development, but can be found here:

https://github.com/bradymiller/openemr/commits/rules_develop

The code of interest is here:
interface/super/rules/base/template/redirect.php

An example of a file that causes a problem can be found here (not the blank line between the © notice and the code):
interface/super/rules/include/header.php

Example usage of the redirection here:
interface/super/rules/controllers/edit/controller.php
in the function:
_action_submit_summary()

To reproduce the bug, navigate to administrator->rules.  Click “add new.” On the next screen, click “cancel” and the redirection code above will yield a white screen.

Thanks,
Ken
http://www.mi-squared.com

kchapple wrote on Monday, April 11, 2011:

… above should read “note the blank line…”

Turn off output buffering in php.ini and check out the php error log for files that are causing problems.

Ken
http://www.mi-squared.com

bradymiller wrote on Tuesday, April 12, 2011:

hi,
Recommend making it work without requiring the setting of output_buffering. Sounds like a place to start is removing the blank lines after the comment blocks.
-brady

bradymiller wrote on Tuesday, April 12, 2011:

Rod also brings up a good point regarding top.restoreSession() function calls. See here for details:
http://www.openmedsoftware.org/wiki/OpenEMR_System_Architecture#PHP_Sessions_and_Browser_Windows

kchapple wrote on Tuesday, April 12, 2011:

I will ask Aron about the best place to put a call to restoreSession(). With the MVC in place, it may only need to be called in one place to affect every script.

Ken
http://www.mi-squared.com