-
-
Save amenpunk/9a33068f8056c504c885fcc9cbf29cfb to your computer and use it in GitHub Desktop.
PHP: Send response and continue processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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