error_log
發送錯誤信息到某個地方
error_log()
函數向服務器錯誤記錄、文件或遠程目標發送錯誤消息。
把錯誤消息發送到web 服務器日誌和郵件賬號:
<?php // 如果錯誤連接至數據庫,則向服務器日誌發送錯誤消息 if ( ! mysqli_connect ( "localhost" , "bad_user" , "bad_password" , "my_db" ) ) { error_log ( "Failed to connect to database!" , 0 ) ; } // 如果用完FOO,向管理員發送電郵 if ( ! ( $foo = allocate_new_foo ( ) ) ) { error_log ( "Oh no! We are out of FOOs!" , 1 , "[email protected]" ) ; } ?>
error_log ( message , type , destination , headers ) ;
參數 | 描述 |
---|---|
message | 必需。規定要記錄的錯誤消息。 |
type |
可選。規定錯誤應該發送到何處。可能的值:
|
destination | 可選。規定錯誤消息的目標。該值由type參數的值決定。 |
headers |
可選。規定額外的頭,比如From、Cc 和Bcc。該信息類型使用了mail() 的同一個內置函數。 僅當message_type設置為1 的時候使用。 應當使用CRLF (\r\n) 來分隔多個頭。 |