导航首页 » 技术教程 » PHP:ignore_user_abort()的用法_misc函数
PHP:ignore_user_abort()的用法_misc函数 153 2023-12-15   

ignore_user_abort

(PHP 4, PHP 5)

ignore_user_abort — 设置客户端断开连接时是否中断脚本的执行

说明

int ignore_user_abort ([ string $value ] )

设置客户端断开连接时是否中断脚本的执行

PHP以命令行脚本执行时,当脚本终端结束,脚本不会被立即中止,除非设置 valueTRUE,否则脚本输出任意字符时会被中止。

参数

value

如果设置了该值,函数会把 ignore_user_abort ini的值设置为 value。 如果未设置该值,函数不会改变设置,仅会返回之前的设置。

返回值

以整型返回之前的设置

范例

Example #1 一个ignore_user_abort()的例子

<?php
// Ignore user aborts and allow the script
// to run forever
ignore_user_abort(true);
set_time_limit(0);

echo 'Testing connection handling in PHP';

// Run a pointless loop that sometime 
// hopefully will make us click away from 
// page or click the "Stop" button.
while(1)
{
    // Did the connection fail?
    if(connection_status() != CONNECTION_NORMAL)
    {
        break;
    }

    // Sleep for 10 seconds
    sleep(10);
}

// If this is reached, then the 'break' 
// was triggered from inside the while loop

// So here we can log, or perform any other tasks
// we need without actually being dependent on the 
// browser.
?>

注释

在PHP尝试发送信息到客户端之前,不会检测到用户是否已中断连接。 仅使用 echo 语句不能确保信息已发送,参见 flush() 函数。

参见

connection_aborted() - 检查客户端是否已经断开 connection_status() - 返回连接的状态位 Connection Handling 关于PHP连接处理的完整描述。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103