PHP构建监视服务的方法_第1页
PHP构建监视服务的方法_第2页
PHP构建监视服务的方法_第3页
PHP构建监视服务的方法_第4页
PHP构建监视服务的方法_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、PHP构建监视服务的方法 PHP监视服务记录程序应该能够支持任意的服务检查(例如,HTTP和FTP服务)并且能够以任意方式(通过电子邮件,输出到一个日志文件,等等)记录事件。你当然想让它以一个守护程序方式运行;所以,你应该请求它输出其完整的当前状态。以下是我为大家搜索整理的PHP构建监视服务的方法,希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网! 一个服务需要实现下列抽象类:abstract class ServiceCheck const FAILURE = 0;const SUCCESS = 1;protected $timeout = 30;protected $nex

2、t_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 _cons

3、truct($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->

4、;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-&g

5、t;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)$

6、this->loggers = $logger;上面的_call()重载方法提供对一个ServiceCheck对象的参数的只读存取操作:· timeout-在引擎终止检查之前,这一检查能够挂起多长时间。· next_attempt-下次尝试连接到服务器的时间。· current_status-服务的当前状态:SUCCESS或FAILURE。· previous_status-当前状态之前的状态。· frequency-每隔多长时间检查一次服务。· description-服务描述。· consecutive_failures-自从上次成功以来,服务检查连续失败的次数。· status_time-服务被检查的最后时间。· failure_time-如果状态为FAILED,则它代表发生失败的时间。这个类还实现了观察者模式,允许ServiceLogger类型的对象注册自身,然后当调用log_current_status()或log_service_event()时调用它。这里实现的关键函数是run(),它负责定义应该

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论