Farzher
Farzher

Reputation: 14593

PHP close HTTP connection then continue processing?

Why is the last line of this function required to make this work? I don't understand what's going on here. It does work though.

function close_connection() {
    // if we're using sessions this stops them from hanging on other requests
    session_write_close();
    // get the content length from the buffer (the whole point of the buffer)
    header('Content-Length: 0');
    // close the connection
    header('Connection: close');
    // flush the buffers to the screen
    flush();

    // connection closing doesn't work without this. I don't know why
    echo ' ';
}

Upvotes: 2

Views: 347

Answers (1)

blowdoof
blowdoof

Reputation: 141

Headers are sent whenever the first byte is output to the browser.
You could also try to use ob_end_flush();

Upvotes: 1

Related Questions