0

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?

LordZardeck
  • 7,953
  • 19
  • 62
  • 119
  • Any of these help? http://stackoverflow.com/questions/138374/close-a-connection-early – dr Hannibal Lecter Jun 08 '12 at 13:45
  • nope, if you read my question and the code provided, i'm already doing that. – LordZardeck Jun 08 '12 at 16:44
  • By "that", you mean the question, the answers, and all the comments on the linked pages? I think you're not doing _everything_ they mentioned, for example this comment: http://www.php.net/manual/en/features.connection-handling.php#104541 – dr Hannibal Lecter Jun 08 '12 at 17:45
  • "If you just want a script that will instantly disconnect the browser " - not what i'm wanting to do. I need to send content to the client THEN disconnect – LordZardeck Jun 08 '12 at 17:59
  • Seriously? You can't see how that comment contains the answer to your problem? – dr Hannibal Lecter Jun 08 '12 at 18:28
  • no, because I need to send data. Content-Length: 0 tells the browser there is nothing to read. besides, I already tried that. – LordZardeck Jun 11 '12 at 00:31
  • Yes, and *because* you need to send data, you're not going to send Content-Length: 0, you're going to get the length of the data you're sending and send that instead of the zero. Shown here: http://stackoverflow.com/a/1773248/78928 and here: http://www.php.net/manual/en/features.connection-handling.php#71172 – dr Hannibal Lecter Jun 11 '12 at 07:23
  • using `ob_get_length()` gave me a content-size of 0 – LordZardeck Jun 11 '12 at 07:28

0 Answers0