Skip to content

Instantly share code, notes, and snippets.

@kfriend
Created March 11, 2016 01:35
Show Gist options
  • Select an option

  • Save kfriend/e8ffd86d6f489c901789 to your computer and use it in GitHub Desktop.

Select an option

Save kfriend/e8ffd86d6f489c901789 to your computer and use it in GitHub Desktop.
PHP: Send response and continue processing
<?php
// Buffer all upcoming output...
ob_start();
// Send your response.
echo "Testing response";
// Get the size of the output.
$size = ob_get_length();
// Disable compression (in case content length is compressed).
header("Content-Encoding: none");
// Set the content length of the response.
header("Content-Length: {$size}");
// Close the connection.
header("Connection: close");
// Flush all output.
ob_end_flush();
ob_flush();
flush();
// Close current session (if it exists).
if (session_id()) {
session_write_close();
}
sleep(30);
file_put_contents('/tmp/foo', 'testing');
@GauravPunani

Copy link
Copy Markdown

really helpfull ! worked exactly as expected

@Mahmoud-Roo

Copy link
Copy Markdown

thank you very much, i`m old in github but this is my first comment in all github, Because you saved me so much time,
thanks again <3 <3 <3

@josua99

josua99 commented Feb 27, 2025

Copy link
Copy Markdown

it works really, thanks very very much ๐ŸŽ‰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment