기타 ignore_user_abort

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

ignore_user_abort — 클라이언트 연결 해제가 스크립트 실행을 중단해야 하는지 여부를 설정합니다.


설명

ignore_user_abort(?bool $enable = null): int

클라이언트 연결 해제로 인해 스크립트가 중단되어야 하는지 여부를 설정합니다.

PHP를 명령줄 스크립트로 실행하고 스크립트가 종료되지 않고 스크립트의 tty가 사라지면 enabletrue로 설정되지 않는 한 다음에 쓰기를 시도할 때 스크립트는 죽습니다.


매개변수

enable
설정되고 null이 아닌 경우 이 함수는 ignore_user_abort ini 설정을 지정된 enable로 설정합니다. 그렇지 않으면 이 함수는 변경하지 않고 이전 설정만 반환합니다.

반환 값

이전 설정을 정수로 반환합니다.


변경 로그

버전 설명
8.0.0 enable은 이제 nullable입니다.

Examples

예제 #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()를 참조하세요.


기타