建立一個函數(check_abort()),在客戶機終止腳本時寫入一條日誌訊息:
<?phpfunction check_abort() { if (connection_aborted()) error_log ("Script $GLOBALS[SCRIPT_NAME]" . "$GLOBALS[SERVER_NAME] was aborted by the user."); }// Some script to be executed here// Call the check_abort function when the script endsregister_shutdown_function("check_abort");?>connection_aborted() 函數檢查是否已中斷客戶端。
connection_aborted()
傳回值: | 如果已終止連線則傳回1,否則回傳0。 |
---|---|
PHP 版本: | 4+ |