預警能夠理解成咱們平常生活中的體檢,每一個人無論是富貴,仍是貧窮,有一個健康的身體纔是事業和生活的基礎。php
項目的健康咱們形象比喻成「1」,項目的N多子功能/子模塊,好比登陸模塊、註冊模塊等都是「1」後面的「0」,若是項目都出問題了(好比 Http Status Code 502, 頁面或者接口響應慢),至關於前面的「1」已經不存在了,即便後面再多的「0」也沒有任何意義。html
從醫學的名詞來表述,包括了三個方面:redis
關於 Asf 框架的入門教程,請看這裏 >>> Get Start
關於 Asf 框架支持的配置項及配置詳情,請看這裏 >>> Get Startapi
Asf PHP擴展框架已經內置了一套預警機制,預警範圍包括了兩個方面,每個方面又包括兩種不一樣的預警處理方法。app
PHP腳本執行異常預警框架
Fatal Error | Warning | Notice | Strict | Deprecated | Unknown Error |
---|---|---|---|---|---|
E_PARSE | E_WARNING | E_NOTICE | E_STRICT | E_DEPRECATED | E_OTHERS |
E_ERROR | E_USER_WARNING | E_USER_NOTICE | - | - | - |
E_CORE_ERROR | E_CORE_WARNING | - | - | - | - |
E_COMPILE_ERROR | E_COMPILE_WARNING | - | - | - | - |
E_USER_ERROR | E_RECOVERABLE_ERROR | - | - | - | - |
PHP腳本執行時間耗時預警 (非CLI模式下)curl
配置項 | 類型 | 默認值 (秒) | 含義 |
---|---|---|---|
asf.dispathcer.timeout.max_script_time | double | 1.0 | 腳本超時預警 |
asf.dispathcer.timeout.max_db_time | double | 0.1 | SQL超時預警 |
asf.dispathcer.timeout.max_cache_time | double | 0.1 | NoSQL超時預警 |
asf.dispathcer.timeout.max_curl_time | double | 0.1 | CURL超時預警 |
本地日誌記錄方案,支持 Log Buffer,性能指標請看這裏 >>> Get Start函數
日誌格式規範請參考這裏 >>> Get Start性能
[dongshuang@box3 /data/www/box3.cn/public]$ cat index.php <?php use Asf\Application as App; $configs = array( 'asf' => array( 'root_path' => dirname(__DIR__) . '/apps', 'log_path' => '/data/logs', /* 日誌保存目錄,寫入權限 */ 'dispatcher' => [ 'log' => ['err' => 1] /* 開啓 */ ] ) ); $app = new App($configs); $app->run();
[dongshuang@box3 /data/logs]$ tailf Asf_Err_Log 2019-02-22 16:01:11 Asia/Shanghai | NOTICE | 28984 | Notice: Undefined variable: b in /data/www/box3.cn/apps/Bootstrap.php on line 21 2019-02-22 16:01:11 Asia/Shanghai | WARNING | 31486 | Warning: include(test.php): failed to open stream: No such file or directory in /data/www/box3.cn/apps/Bootstrap.php on line 20 2019-02-22 16:02:24 Asia/Shanghai | ERROR | 4137 | Fatal Error: Asf\Application::run() No method listaaction in DeviceService in /data/www/box3.cn/public/index.php on line 23 Stack trace: ## settled_uri = /v1/device/lista #0 /data/www/box3.cn/public/index.php(23): Asf\Application->run() #1 {main}
[dongshuang@box3 /data/www/box3.cn/public]$ cat index.php <?php use Asf\Application as App; $configs = array( 'asf' => array( 'root_path' => dirname(__DIR__) . '/apps', 'log_path' => '/data/logs', /* 日誌保存目錄,寫入權限 */ 'dispatcher' => [ 'log' => ['timeout' => 1] /* 開啓 */ ] ) ); $app = new App($configs); $app->run();
[dongshuang@box3 /data/logs]$ tailf Asf_Timeout_Log 2019-02-25 09:06:48 UTC | INFO | 26026 | 127.0.0.1:6379 Redis::set(110) executing too slow 0.201406 sec 2019-02-25 09:06:48 UTC | INFO | 26026 | 127.0.0.1:6379 Redis::get(111) executing too slow 0.201349 sec 2019-02-25 09:06:48 UTC | INFO | 26026 | /index/redis executing too slow 1.008510 sec
[dongshuang@box3 /data/www/box3.cn/public]$ cat index.php <?php use Asf\Application as App; function myErrorHandler($errno, $errstr, $errfile, $errline) { var_dump($errno, $errstr, $errfile, $errline); } $configs = array( 'asf' => array( 'root_path' => dirname(__DIR__) . '/apps', ) ); $app = new App($configs); $app->setErrorHandler('myErrorHandler'); $app->run();
int(999) string(33) "Fatal Error: Class 'ck' not found" string(53) "/data/www/box3.cn/apps/api/services/Index.php" int(42)
[dongshuang@box3 /data/www/box3.cn/public]$ cat index.php <?php use Asf\Application as App; function myTimeoutHandler($errno, $errstr) { var_dump($errno, $errstr); } $configs = array( 'asf' => array( 'root_path' => dirname(__DIR__) . '/apps', ) ); $app = new App($configs); $app->setTimeoutHandler('myTimeoutHandler'); $app->run();
int(976) string(44) "/index/redis executing too slow 0.508643 sec"
感謝你們的閱讀,但願能給你們帶來幫助,若是使用中有疑問請聯繫咱們,固然了咱們也能夠聊點更好玩的 ^_^url