Created
February 12, 2021 16:25
-
-
Save ahamilton9/ff1115c221fba04a9d0c41c86aeb3c66 to your computer and use it in GitHub Desktop.
Respond early to a PHP request and keep processing
This file contains hidden or 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 | |
// Provide a success response early | |
// Modified from: https://stackoverflow.com/a/42245266 | |
function respondEarly() { | |
if(session_id()) {session_write_close();} | |
if(is_callable('fastcgi_finish_request')) { | |
fastcgi_finish_request(); | |
return; | |
} | |
ignore_user_abort(true); | |
ob_start(); | |
$serverProtocol = filter_input(INPUT_SERVER, 'SERVER_PROTOCOL', FILTER_SANITIZE_STRING); | |
header($serverProtocol . ' 200 OK'); | |
header('Content-Encoding: none'); | |
header('Content-Length: ' . ob_get_length()); | |
header('Connection: close'); | |
ob_end_flush(); | |
flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment