Last active
December 12, 2015 04:48
-
-
Save pjbeardsley/4716592 to your computer and use it in GitHub Desktop.
PHP: long running process with closed connection
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 | |
set_time_limit(0); | |
ignore_user_abort(TRUE); | |
// return the headers and close the connection, but keep running. | |
ob_start(); | |
fJSON::output(array('success' => 'T', 'message' => 'The full synchronization process has started.')); | |
$length = ob_get_length(); | |
header("Content-Length: $length"); | |
header('Connection: close'); | |
ob_end_flush(); | |
ob_flush(); | |
flush(); | |
// if you're using sessions, this prevents subsequent requests | |
// from hanging while the background process executes | |
if (session_id()) session_write_close(); | |
// do work... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment