ignore_user_abort
(PHP 4, PHP 5, PHP 7, PHP 8)
ignore_user_abort — 設定客戶端斷開連線時是否中斷指令碼的執行
說明
   ignore_user_abort(bool 
  $value = ?): int設定客戶端斷開連線時是否中斷指令碼的執行
   PHP 以命令列指令碼執行時,當指令碼終端結束,指令碼不會被立即中止,除非設定 value 為 true,否則指令碼輸出任意字元時會被中止。
返回值
以整型返回之前的設定
範例
示例 #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連線處理的完整描述。