My script is called by server. From server I\'ll receive ID_OF_MESSAGE
and TEXT_OF_MESSAGE
.
In my script I\'ll handle incoming text and ge
I've seen a lot of responses on here that suggest using ignore_user_abort(true);
but this code is not necessary. All this does is ensure your script continues executing before a response is sent in the event that the user aborts (by closing their browser or pressing escape to stop the request). But that's not what you're asking. You're asking to continue execution AFTER a response is sent. All you need is the following:
// Buffer all upcoming output...
ob_start();
// Send your response.
echo "Here be 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();
// Start your background work here.
...
If you're concerned that your background work will take longer than PHP's default script execution time limit, then stick set_time_limit(0);
at the top.