我目前有一个 AJAX 请求发送到 sendMail.php,它立即关闭连接(使用标头Connection: Close)并继续处理大约 30 秒。
但是我现在遇到的问题是,当同一个客户端尝试从该服务器加载任何 PHP 页面时,它必须等到 sendMail.php 完成处理。
有没有办法解决?
我正在阅读其他一些可能与会话相关的 SO 问题,但我没有使用任何会话,我什至尝试在 sendMail.php 脚本的开头调用session_write_close() 。
示例代码(这是hacky并且完成了,但它有效):
//File: SendMail.php
//error_reporting(E_ALL);
error_reporting(0);
session_write_close();
set_time_limit(0);
ignore_user_abort(1);
ignore_user_abort(true);
ini_set('ignore_user_abort','1');
apache_setenv('no-gzip', 1);
apache_setenv('KeepAlive',0);
ini_set('zlib.output_compression', 0);
ini_set('output_buffering', 0);
$size = ob_get_length();
// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: Close');
// flush all output
ignore_user_abort(true);
ob_end_flush();
ob_flush();
flush();
sleep(30);//The real code has more stuff, but just for example lets just say it sleeps for 30 seconds
其余参考资料是通过 GET 进行的正常导航。