Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Controller_Action_Helper_BrowserDisconnect Class Reference

Handles disconnecting from the browser to allow long-running code to complete behind the scenes. More...

Inheritance diagram for P4Cms_Controller_Action_Helper_BrowserDisconnect:
P4Cms_Controller_Action_Helper_Redirector

List of all members.

Public Member Functions

 disconnect ($redirectTarget=null, $timeLimit=null)
 Disconnect from the browser to begin long-running tasks.

Protected Attributes

 $_timeLimit = 10

Detailed Description

Handles disconnecting from the browser to allow long-running code to complete behind the scenes.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

P4Cms_Controller_Action_Helper_BrowserDisconnect::disconnect ( redirectTarget = null,
timeLimit = null 
)

Disconnect from the browser to begin long-running tasks.

Parameters:
string$redirectTargetThe action to redirect the user to, if applicable.
int$timeLimitThe 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();
    }

Member Data Documentation

P4Cms_Controller_Action_Helper_BrowserDisconnect::$_timeLimit = 10 [protected]

The documentation for this class was generated from the following file: