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

发表日期:2021-07-01 10:15:43 | 来源: | | 浏览(936) 分类:杂项 函数

ignore_user_abort

(PHP 4, PHP 5, PHP 7, PHP 8)

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

说明

ignore_user_abort(bool $value = ?): int

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

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

参数

value

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

返回值

以整型返回之前的设置

范例

示例 #1 ignore_user_abort()例子

<?php 
// Ignore user aborts and allow the script// to run foreverignore_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() 函数。

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。