1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. PHP構(gòu)建監(jiān)視服務(wù)的方法是什么

        時(shí)間:2020-11-23 18:49:59 PHP 我要投稿

        PHP構(gòu)建監(jiān)視服務(wù)的方法是什么

          【提要】本篇《PHP構(gòu)建監(jiān)視服務(wù)的方法》特別為需要方法編程學(xué)習(xí)的朋友收集整理的,僅供參考。內(nèi)容如下:

          PHP監(jiān)視服務(wù)記錄程序應(yīng)該能夠支持任意的服務(wù)檢查(例如,HTTP和FTP服務(wù))并且能夠以任意方式(通過電子郵件,輸出到一個(gè)日志文件,等等)記錄事件。你當(dāng)然想讓它以一個(gè)守護(hù)程序方式運(yùn)行;所以,你應(yīng)該請(qǐng)求它輸出其完整的當(dāng)前狀態(tài)。以下是小編為大家搜索整理的PHP構(gòu)建監(jiān)視服務(wù)的方法,希望能給大家?guī)韼椭?

          一個(gè)服務(wù)需要實(shí)現(xiàn)下列抽象類:

          abstract class ServiceCheck {

          const FAILURE = 0;

          const SUCCESS = 1;

          protected $timeout = 30;

          protected $next_attempt;

          protected $current_status = ServiceCheck::SUCCESS;

          protected $previous_status = ServiceCheck::SUCCESS;

          protected $frequency = 30;

          protected $description;

          protected $consecutive_failures = 0;

          protected $status_time;

          protected $failure_time;

          protected $loggers = array();

          abstract public function __construct($params);

          public function __call($name, $args)

          {

          if(isset($this->$name)) {

          return $this->$name;

          }

          }

          public function set_next_attempt()

          {

          $this->next_attempt = time() + $this->frequency;

          }

          public abstract function run();

          public function post_run($status)

          {

          if($status !== $this->current_status) {

          $this->previous_status = $this->current_status;

          }

          if($status === self::FAILURE) {

          if( $this->current_status === self::FAILURE ) {

          $this->consecutive_failures++;

          }

          else {

          $this->failure_time = time();

          }

          }

          else {

          $this->consecutive_failures = 0;

          }

          $this->status_time = time();

          $this->current_status = $status;

          $this->log_service_event();

          }

          public function log_current_status()

          {

          foreach($this->loggers as $logger) {

          $logger->log_current_status($this);

          }

          }

          private function log_service_event()

          {

          foreach($this->loggers as $logger) {

          $logger->log_service_event($this);

          }

          }

          public function register_logger(ServiceLogger $logger)

          {

          $this->loggers[] = $logger;

          }

          }

          上面的__call()重載方法提供對(duì)一個(gè)ServiceCheck對(duì)象的'參數(shù)的只讀存取操作:

          · timeout-在引擎終止檢查之前,這一檢查能夠掛起多長(zhǎng)時(shí)間。

          · next_attempt-下次嘗試連接到服務(wù)器的時(shí)間。

          · current_status-服務(wù)的當(dāng)前狀態(tài):SUCCESS或FAILURE。

          · previous_status-當(dāng)前狀態(tài)之前的狀態(tài)。

          · frequency-每隔多長(zhǎng)時(shí)間檢查一次服務(wù)。

          · description-服務(wù)描述。

          · consecutive_failures-自從上次成功以來,服務(wù)檢查連續(xù)失

          敗的次數(shù)。

          · status_time-服務(wù)被檢查的最后時(shí)間。

          · failure_time-如果狀態(tài)為FAILED,則它代表發(fā)生失敗的時(shí)間。

          這個(gè)類還實(shí)現(xiàn)了觀察者模式,允許ServiceLogger類型的對(duì)象注冊(cè)自身,然后當(dāng)調(diào)用log_current_status()或log_service_event()時(shí)調(diào)用它。

          這里實(shí)現(xiàn)的關(guān)鍵函數(shù)是run(),它負(fù)責(zé)定義應(yīng)該怎樣執(zhí)行檢查。如果檢查成功,它應(yīng)該返回SUCCESS;否則返回FAILURE。

        【PHP構(gòu)建監(jiān)視服務(wù)的方法是什么】相關(guān)文章:

        1.php是什么

        2.PHP構(gòu)建自定義搜索引擎的方法總結(jié)

        3.php在服務(wù)器執(zhí)行exec命令失敗的解決方法-php技巧

        4.php是什么格式

        5.如何使用PHP構(gòu)建一個(gè)高性能的彈幕后端服務(wù)

        6.php是什么型語(yǔ)言

        7.php是什么類型語(yǔ)言

        8.php是什么意思

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>