(PHP 4, PHP 5, PHP 7, PHP 8)
ignore_user_abort — 設置客戶(hù)端斷開(kāi)連接時(shí)是否中斷腳本的執行
$value
= ?): int設置客戶(hù)端斷開(kāi)連接時(shí)是否中斷腳本的執行
PHP 以命令行腳本執行時(shí),當腳本終端結束,腳本不會(huì )被立即中止,除非設置 value
為 true
,否則腳本輸出任意字符時(shí)會(huì )被中止。
value
如果設置了該值,函數會(huì )把 ignore_user_abort ini 的值設置為 value
。
如果未設置該值,函數不會(huì )改變設置,僅會(huì )返回之前的設置。
以整型返回之前的設置
示例 #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嘗試發(fā)送信息到客戶(hù)端之前,不會(huì )檢測到用戶(hù)是否已中斷連接。 僅使用 echo 語(yǔ)句不能確保信息已發(fā)送,參見(jiàn) flush() 函數。