I need to run a REALLY long process in the background. The program is supposed to send the request details to the server, and the server return a process id. At a certain interval the program is supposed send a check request with that id to see if that process is completed. Everything works okay except for the fact I can't get the connection to close and the client to receive the ID until the process is finished. I tried using this article: http://codehackit.blogspot.com/2011/07/how-to-kill-http-connection-and.html but it still doesn't close the connection. Here's what I have going so far:
$id = time();
$this->Session->write(sprintf('LongProcess.%s.finished', $id), false);
$this->Response->data(array('process_id' => $id));
ob_end_clean();
ob_start();
$this->Response->render();
header("Connection: close");
ob_end_flush();
ob_flush();
flush();
ignore_user_abort(true);
set_time_limit(0);
// Do really long processing here
To help explain, $this->Response
is a component I wrote to handle ajax calls. the data()
method adds data to an array in the component. the render()
method takes and formats all the data to a specific specification used my the client and renders the output using $this->controller->render('/Elements/response');
.
How can I force the connection to close so the client can continue doing other things?