note 107027 modified in features.connection-handling by danbrown

From: Date: Tue, 03 Jan 2012 21:50:18 +0000
Subject: note 107027 modified in features.connection-handling by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185295@lists.php.net to get a copy of this message
This simple function outputs a string and closes the connection. It considers compression using "ob_gzhandler" It took me a little while to put this all together, mostly because setting the encoding to none, as some people noted here, didn't work. <?php function outputStringAndCloseConnection2($stringToOutput) { set_time_limit(0); ignore_user_abort(true); // buffer all upcoming output - make sure we care about compression: if(!ob_start("ob_gzhandler")) ob_start(); echo $stringToOutput; // get the size of the output $size = ob_get_length(); // send headers to tell the browser to close the connection header("Content-Length: $size"); header('Connection: close'); // flush all output ob_end_flush(); ob_flush(); flush(); // close current session if (session_id()) session_write_close(); } ?> --was-- This simple function outputs a string and closes the connection. It considers compression using "ob_gzhandler" It took me a little while to put this all together, mostly because setting the encoding to none, as some people noted here, didn't work. function outputStringAndCloseConnection2($stringToOutput) { set_time_limit(0); ignore_user_abort(true); // buffer all upcoming output - make sure we care about compression: if(!ob_start("ob_gzhandler")) ob_start(); echo $stringToOutput; // get the size of the output $size = ob_get_length(); // send headers to tell the browser to close the connection header("Content-Length: $size"); header('Connection: close'); // flush all output ob_end_flush(); ob_flush(); flush(); // close current session if (session_id()) session_write_close(); } http://php.net/manual/en/features.connection-handling.php

« previous php.notes (#185295) next »