|
Perforce Chronicle 2012.2/486814
API Documentation
|
Handles disconnecting from the browser to allow long-running code to complete behind the scenes. More...
Public Member Functions | |
| disconnect ($redirectTarget=null, $timeLimit=null) | |
| Disconnect from the browser to begin long-running tasks. | |
Protected Attributes | |
| $_timeLimit = 10 | |
Handles disconnecting from the browser to allow long-running code to complete behind the scenes.
| P4Cms_Controller_Action_Helper_BrowserDisconnect::disconnect | ( | $ | redirectTarget = null, |
| $ | timeLimit = null |
||
| ) |
Disconnect from the browser to begin long-running tasks.
| string | $redirectTarget | The action to redirect the user to, if applicable. |
| int | $timeLimit | The time limit for long-running tasks in minutes. |
{
// set time limit for script execution
$timeLimit = ($timeLimit) ?: $this->_timeLimit;
set_time_limit(60 * $timeLimit);
ignore_user_abort(true);
// Clear output buffer and save output; while loop handles potential multiple levels of output buffering.
$output = '';
while (ob_get_level()) {
$output.= ob_get_clean();
}
if ($redirectTarget) {
$this->setExit(false);
$this->gotoSimple($redirectTarget);
}
// Disable gzip compression in apache, as it can result in this request being buffered until it is complete,
// regardless of other settings.
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', 1);
}
// If not redirecting, send appropriate headers and output.
header('Connection: close');
header('Content-length: ' . strlen($output));
$this->getResponse()->sendHeaders();
$this->getResponse()->clearHeaders();
echo $output;
session_write_close();
flush();
}
P4Cms_Controller_Action_Helper_BrowserDisconnect::$_timeLimit = 10 [protected] |