【发布时间】:2014-01-27 16:56:57
【问题描述】:
当客户端关闭数据传输时,我如何在我的 php 代码中知道?
我在 stackoverflow 上找到了这段代码(如下),但我想在客户端关闭窗口时将文本写入文件...
<?php
header('Content-Encoding', 'chunked');
header('Transfer-Encoding', 'chunked');
header('Content-Type', 'text/html');
header('Connection', 'keep-alive');
ob_flush();
flush();
$p = ""; //padding
for ($i=0; $i < 1024; $i++) {
$p .= " ";
};
echo $p;
ob_flush();
flush();
for ($i = 0; $i < 10000; $i++) {
echo "string";
ob_flush();
flush();
sleep(2);
}
?>
【问题讨论】: