Force output buffers to be flushed, if they're turned on.

If output buffering is turned on, PHP can be a bit slack about sending
the data to the client before closing the connection with exit(). These
changes ensure we call ob_flush() before we leave.  We call @ob_flush()
so we don't get noisy warnings when output buffering is off...
This commit is contained in:
Andrew McMillan 2011-11-02 18:43:10 +13:00
parent c093419591
commit b50b2d82ea
13 changed files with 24 additions and 23 deletions

View File

@ -24,7 +24,7 @@ if ( ! @include_once( $code_file ) ) {
$c->messages[] = sprintf('No page found to %s %s%s%s', $action, ($action == 'browse' ? '' : 'a '), $component, ($action == 'browse' ? 's' : '')); $c->messages[] = sprintf('No page found to %s %s%s%s', $action, ($action == 'browse' ? '' : 'a '), $component, ($action == 'browse' ? 's' : ''));
include('page-header.php'); include('page-header.php');
include('page-footer.php'); include('page-footer.php');
exit(0); @ob_flush(); exit(0);
} }
include('page-header.php'); include('page-header.php');

View File

@ -26,6 +26,7 @@ function early_exception_handler($e) {
foreach( $trace AS $k => $v ) { foreach( $trace AS $k => $v ) {
printf( "%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') ); printf( "%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') );
} }
@ob_flush();
} }
set_exception_handler('early_exception_handler'); set_exception_handler('early_exception_handler');
@ -89,7 +90,7 @@ if ( ! @include_once('AWLUtilities.php') ) {
} }
if ( ! @include_once('AWLUtilities.php') ) { if ( ! @include_once('AWLUtilities.php') ) {
echo "Could not find the AWL libraries. Are they installed? Check your include_path in php.ini!\n"; echo "Could not find the AWL libraries. Are they installed? Check your include_path in php.ini!\n";
exit; @ob_flush(); exit(0);
} }
} }
@ -145,7 +146,7 @@ else if ( @file_exists('config/config.php') ) {
} }
else { else {
include('davical_configuration_missing.php'); include('davical_configuration_missing.php');
exit; @ob_flush(); exit(0);
} }
$config_warnings = trim(ob_get_contents()); $config_warnings = trim(ob_get_contents());
ob_end_clean(); ob_end_clean();

View File

@ -17,17 +17,17 @@ if ( isset($_SERVER['PATH_INFO']) && preg_match( '{^(/favicon.ico|davical.css|(i
else { else {
fpassthru($fh); fpassthru($fh);
} }
exit(0); @ob_flush(); exit(0);
} }
require_once('./always.php'); require_once('./always.php');
if ( isset($_SERVER['PATH_INFO']) && preg_match( '{^/\.well-known/(.+)$}', $_SERVER['PATH_INFO'], $matches ) ) { if ( isset($_SERVER['PATH_INFO']) && preg_match( '{^/\.well-known/(.+)$}', $_SERVER['PATH_INFO'], $matches ) ) {
require ('well-known.php'); require ('well-known.php');
exit(0); @ob_flush(); exit(0);
} }
elseif ( isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/autodiscover/autodiscover.xml' ) { elseif ( isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/autodiscover/autodiscover.xml' ) {
require ('autodiscover-handler.php'); require ('autodiscover-handler.php');
exit(0); @ob_flush(); exit(0);
} }
function logRequestHeaders() { function logRequestHeaders() {
@ -102,7 +102,7 @@ if ( ! ($request->IsPrincipal() || isset($request->collection) || $request->meth
$redirect_url = ConstructURL('/caldav.php'.$matches[1]); $redirect_url = ConstructURL('/caldav.php'.$matches[1]);
dbg_error_log( 'LOG WARNING', 'Redirecting %s for "%s" to "%s"', $request->method, $request->path, $redirect_url ); dbg_error_log( 'LOG WARNING', 'Redirecting %s for "%s" to "%s"', $request->method, $request->path, $redirect_url );
header('Location: '.$redirect_url ); header('Location: '.$redirect_url );
exit(0); @ob_flush(); exit(0);
} }
} }

View File

@ -4,7 +4,7 @@ if ( $_SERVER['REQUEST_METHOD'] != "GET" && $_SERVER['REQUEST_METHOD'] != "POST"
* If the request is not a GET or POST then they must really want caldav.php! * If the request is not a GET or POST then they must really want caldav.php!
*/ */
include("./caldav.php"); include("./caldav.php");
exit; // Not that it should return from that! @ob_flush(); exit(0); // Not that it should return from that!
} }
include("./always.php"); include("./always.php");

View File

@ -21,7 +21,7 @@ require_once("caldav-PUT-functions.php");
include_once('check_UTF8.php'); include_once('check_UTF8.php');
if ( !$session->AllowedTo("Admin" ) ) if ( !$session->AllowedTo("Admin" ) )
exit; @ob_flush(); exit(0);
if( function_exists("sync_LDAP") && isset($_POST['Sync_LDAP'])){ if( function_exists("sync_LDAP") && isset($_POST['Sync_LDAP'])){
sync_LDAP(); sync_LDAP();

View File

@ -1201,8 +1201,7 @@ EOSQL;
@dbg_error_log("statistics", "Method: %s, Status: %d, Script: %5.3lfs, Queries: %5.3lfs, URL: %s", @dbg_error_log("statistics", "Method: %s, Status: %d, Script: %5.3lfs, Queries: %5.3lfs, URL: %s",
$this->method, $status, $script_time, $c->total_query_time, $this->path); $this->method, $status, $script_time, $c->total_query_time, $this->path);
} }
@ob_flush(); exit(0);
exit(0);
} }
} }

View File

@ -113,7 +113,7 @@ class DAViCalSession extends Session
|| (isset($c->restrict_admin_port) && $c->restrict_admin_port != $_SERVER['SERVER_PORT'] ) ) { || (isset($c->restrict_admin_port) && $c->restrict_admin_port != $_SERVER['SERVER_PORT'] ) ) {
header('Location: caldav.php'); header('Location: caldav.php');
dbg_error_log( 'LOG WARNING', 'Access to "%s" via "%s:%d" rejected.', $_SERVER['REQUEST_URI'], $current_domain, $_SERVER['SERVER_PORT'] ); dbg_error_log( 'LOG WARNING', 'Access to "%s" via "%s:%d" rejected.', $_SERVER['REQUEST_URI'], $current_domain, $_SERVER['SERVER_PORT'] );
exit(0); @ob_flush(); exit(0);
} }
if ( isset($c->restrict_admin_roles) && $roles == '' ) $roles = $c->restrict_admin_roles; if ( isset($c->restrict_admin_roles) && $roles == '' ) $roles = $c->restrict_admin_roles;
if ( $this->logged_in && $roles == '' ) return; if ( $this->logged_in && $roles == '' ) return;
@ -156,7 +156,7 @@ class DAViCalSession extends Session
} }
include('page-footer.php'); include('page-footer.php');
exit; @ob_flush(); exit(0);
} }
} }

View File

@ -88,7 +88,7 @@ class HTTPAuthSession {
header( $auth_header ); header( $auth_header );
echo 'Please log in for access to this system.'; echo 'Please log in for access to this system.';
dbg_error_log( "HTTPAuth", ":Session: User is not authorised: %s ", $_SERVER['REMOTE_ADDR'] ); dbg_error_log( "HTTPAuth", ":Session: User is not authorised: %s ", $_SERVER['REMOTE_ADDR'] );
exit; @ob_flush(); exit(0);
} }

View File

@ -26,6 +26,7 @@ function early_exception_handler($e) {
foreach( $trace AS $k => $v ) { foreach( $trace AS $k => $v ) {
printf( "%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') ); printf( "%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') );
} }
@ob_flush();
} }
set_exception_handler('early_exception_handler'); set_exception_handler('early_exception_handler');
@ -89,7 +90,7 @@ if ( ! @include_once('AWLUtilities.php') ) {
} }
if ( ! @include_once('AWLUtilities.php') ) { if ( ! @include_once('AWLUtilities.php') ) {
echo "Could not find the AWL libraries. Are they installed? Check your include_path in php.ini!\n"; echo "Could not find the AWL libraries. Are they installed? Check your include_path in php.ini!\n";
exit; @ob_flush(); exit(0);
} }
} }
@ -145,7 +146,7 @@ else if ( @file_exists('config/config.php') ) {
} }
else { else {
include('davical_configuration_missing.php'); include('davical_configuration_missing.php');
exit; @ob_flush(); exit(0);
} }
$config_warnings = trim(ob_get_contents()); $config_warnings = trim(ob_get_contents());
ob_end_clean(); ob_end_clean();

View File

@ -299,7 +299,7 @@ function AuthExternalAWL( $username, $password ) {
</body> </body>
</html> </html>
EOERRMSG; EOERRMSG;
exit(1); @ob_flush(); exit(1);
} }
if ( $qry->Exec('Login',__LINE__,__FILE__) && $qry->rows() == 1 ) { if ( $qry->Exec('Login',__LINE__,__FILE__) && $qry->rows() == 1 ) {

View File

@ -14,7 +14,7 @@ $request = new CalDAVRequest();
if ( !isset($c->enable_autodiscover) || ! $c->enable_autodiscover ) { if ( !isset($c->enable_autodiscover) || ! $c->enable_autodiscover ) {
$request->DoResponse( 404 ); $request->DoResponse( 404 );
exit(0); exit(0); // unneccessary
} }
$ns_outlook_req_2006 = "http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006"; $ns_outlook_req_2006 = "http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006";
@ -40,7 +40,7 @@ function errorResponse( $code, $message, $debugdata = '' ) {
ERROR; ERROR;
$request->DoResponse( $code, $response, 'text/xml; charset="utf-8"' ); $request->DoResponse( $code, $response, 'text/xml; charset="utf-8"' );
exit(0); exit(0); // unneccessary
} }

View File

@ -353,6 +353,5 @@ if ( $qry->Commit() ) {
* Or it was all crap. * Or it was all crap.
*/ */
$request->DoResponse( 500 ); $request->DoResponse( 500 );
exit(0); // unneccessary
exit(0);

View File

@ -34,7 +34,7 @@ switch ( $request->path ) {
if ( $c->enable_scheduling != true ) if ( $c->enable_scheduling != true )
{ {
$request->DoResponse( 404, translate('The application program does not understand that request.') ); $request->DoResponse( 404, translate('The application program does not understand that request.') );
exit (); // Does not return
} }
header ( 'iSchedule-Version: 1.0' ); header ( 'iSchedule-Version: 1.0' );
@ -103,5 +103,6 @@ RESPONSE;
</capability-set> </capability-set>
</query-result> </query-result>
RESPONSE; RESPONSE;
exit ( 0 );
@ob_flush(); exit(0);
} }