PHP函數register_shutdown_function的使用樣本

來源:互聯網
上載者:User

標籤:檔案引入   源碼   完成   public   data   curl   參數   info   message   

某些情況下,我們需要在程式執行結束時,做一些後續的處理工作,這個時候,PHP的register_shutdown_function函數就可以幫我們來實現這個功能。
函數簡介
當php程式執行完成後,自動執行register_shutdown_function函數,該函數需要一個參數,用來指定由誰處理這些後續的工作。其中,程式執行完成,分為以下幾種情況:
第一種:php代碼執行過程中發生錯誤
第二種:php代碼順利執行成功
第三種:php代碼運行逾時
第四種:頁面被使用者強制停止

 

程式入口檔案引入

register_shutdown_function(array(‘Error‘, ‘systemError‘));

 

Error類源碼

<?phpclass Error{    public static function systemError()    {        $message = ‘‘;        if ($error = error_get_last()) {            $separator = "\r\n";            $date = date(‘Y-m-d H:i:s‘, time());            $message .= "[".$date."]---message:" . $error[‘message‘] . $separator;            $message .= "file:" . $error[‘file‘] . $separator;            $message .= "line:" . $error[‘line‘] . $separator;            $url = ‘‘;            $data = array(                ‘info‘=>$message,                ‘type‘=>‘bbs‘            );            Helper::curlRequest($url, $data, true, 5);        }else{            //此處處理其它一些商務邏輯        }    }}

 

PHP函數register_shutdown_function的使用樣本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.