Skip to content

Instantly share code, notes, and snippets.

@m4tlch
Forked from kfriend/respond_and_process.php
Created June 13, 2019 16:15
Show Gist options
  • Save m4tlch/02e7c540d4fb3830d748469f9a137555 to your computer and use it in GitHub Desktop.
Save m4tlch/02e7c540d4fb3830d748469f9a137555 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