ignore_user_abort

(PHP 4, PHP 5, PHP 7)

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

说明

ignore_user_abort ([ bool $value ] ) : int

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

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() 函数。

参见