PHP:重定向但继续使用ignore_user_abort(true)处理脚本失败

时间:2014-10-10 14:59:37

标签: php

我有一些我无法弄清楚的问题。这似乎与服务器有关。

我需要做的是 - 当用户提交表单时,他会立即重定向到某个页面,但PHP脚本会继续处理后台的所有表单数据。 代码是这样的:

//if form is submitted start:
//redirect user
header("Location: activity.php");

ob_end_clean();
header("Connection: close");

ignore_user_abort(true);

set_time_limit(1800); //extend process time

ob_start();
header("Content-Length: 0");

ob_end_flush();
flush();

session_write_close();

//Below this line starts the code to process form.

在本地服务器上测试此代码时,一切都按预期工作,用户被重定向到页面activity.php,PHP脚本继续在后台运行。将相同的脚本上传到实时服务器时,没有任何作用。用户未被重定向,页面等待所有内容处理完毕,然后才将用户重定向到activity.php

为什么会这样?我在这个剧本中看不出任何错误。有人可以帮忙吗? 是否需要在服务器上启用某些包?我无法理解为什么这个脚本在一台服务器上工作但在其他服务器上失败。 非常感谢你。

0 个答案:

没有答案