cakephp强制关闭http连接继续运行脚本

时间:2012-06-08 06:23:24

标签: php ajax cakephp forceclose

我需要在后台运行一个非常长的进程。程序应该将请求详细信息发送到服务器,服务器返回进程ID。在某个时间间隔,程序应该发送带有该id的检查请求,以查看该过程是否完成。一切正常,除了我无法获得关闭连接和客户端接收ID,直到过程完成。我尝试使用这篇文章:http://codehackit.blogspot.com/2011/07/how-to-kill-http-connection-and.html但它仍然没有关闭连接。这是我到目前为止所做的事情:

$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

为了帮助解释,$this->Response是我编写的用于处理ajax调用的组件。 data()方法将数据添加到组件中的数组。 render()方法将所有数据格式化为客户端使用的特定规范,并使用$this->controller->render('/Elements/response');呈现输出。

如何强制关闭连接以便客户端可以继续执行其他操作?

0 个答案:

没有答案
相关问题