PHP connection_aborted()无法正常工作 [英] PHP connection_aborted() not working correctly

查看:61
本文介绍了PHP connection_aborted()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

ignore_user_abort(true);
while(!connection_aborted()) {
    // do stuff
}

并且根据PHP文档,它应该一直运行到关闭连接为止,但是由于某种原因,它不会一直运行,而是一直运行直到脚本超时。我在网上四处看看,有人建议添加

and according to the PHP documentation, this should run until the connection is closed, but for some reason, it doesn't, instead it keeps running until the script times out. I've looked around online and some recommended adding

echo chr(0);
flush();

进入循环,但这似乎也不起作用。更糟糕的是,如果我将其保留为

into the loop, but that doesn't seem to do anything either. Even worse, if I just leave it as

while(true) {
    // do stuff
}

在客户端断开连接后,PHP仍继续运行脚本。有谁知道如何使它工作?

PHP still continues to run the script after the client disconnects. Does anyone know how to get this working? Is there a php.ini setting that I'm missing somewhere?

如果重要,我正在运行PHP 5.3.5。

If it matters, I'm running PHP 5.3.5. Thanks in advance!

推荐答案

尝试:

    ignore_user_abort(true);

    echo "Testing connection handling";

    while (1) {
            if (connection_status() != CONNECTION_NORMAL)
                    break;
            sleep(1);
            echo "test";
            flush();
    }

这篇关于PHP connection_aborted()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆