Skip to content

Instantly share code, notes, and snippets.

@amenpunk
Forked from kfriend/respond_and_process.php
Created January 28, 2021 16:22
Show Gist options
  • Save amenpunk/9a33068f8056c504c885fcc9cbf29cfb to your computer and use it in GitHub Desktop.
Save amenpunk/9a33068f8056c504c885fcc9cbf29cfb 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment